<?php
require_once (C_PATH . '/utility.php');

/**
 * main
 * 
 * @package Controller  
 * @author Takuya Kanbara
 * @copyright Takuya Kanbara
 * @version 1.0
 * @access public
 */
 
class export_tables extends spController
{
    var $tUsers;
    var $db;
    var $tSchools;
    var $tTerms;
    var $tClasses;
    
    var $tClassStatisticsEachTerm;
    var $tClassStatisticsEachDay;

    /**
     * main::__construct()
     * 
     * @return
     */
    public function __construct()
    {
        parent::__construct();
       	whoAmI($this);  //check the permission
        if(!$this->user) {
            $this->jump(spUrl('error_page', 'index', array('errno'=>2)));
            return;
        }
        
        
        //初始化模型类
        $this->tUsers = spClass('users');
        $this->tSchools = spClass('schools');
        $this->tClasses = spClass('classes');
        $this->tTerms = spClass('terms');
        
        $this->tClassStatisticsEachTerm = spClass('class_statistics_each_term');
        $this->tClassStatisticsEachDay = spClass('class_statistics_each_day');
        
        $this->db = $this->tUsers;
		
		
		if(!user_is_valid($this, $this->tUsers))
		{
			$this->jump(spUrl('error_page', 'index', array('errno'=>2)));
            return;
		}
        
        $this->schoolid = $this->spArgs('schoolid', -1);
        
        $this->school = $this->tSchools->find(array('id'=> $this->schoolid));
        $terms = $this->tTerms->findAll();
        $this->terms = $terms;
    }

    /**
     * main::index()
     * 
     * @return
     * @abstract 首页
     */
    function index()
    {
			
			$termid = $this->spArgs('termid', 1);//默认第一学期
      $this->termid = $termid;   

			$sql = "SELECT COUNT(schoolname) as count, zone FROM schools GROUP BY zone";
			$zones = $this->db->findSql($sql);
			$p1=$p2=$p3=$p4=$p5=0;
			foreach($zones as $k=>$v)
			{
				$zones[$k]['schools'] = $this->tSchools->findAll(array('zone'=>$v['zone']));
				$a1=$a2=$a3=$a4=$a5=0;
				foreach($zones[$k]['schools'] as $item){
					$schoolid=$item["id"];
					$sql_term="select * from class_statistics_each_term where  classid in(select id from classes where schoolid=$schoolid) and termid=$termid";
					
					$ary_list=$this->db->findSql($sql_term);
					foreach($ary_list as $row){
					
						$a1+=$row["a0_0"]+$row["a1_0"];//所有人数
						$p1+=$row["a0_0"]+$row["a1_0"];
						$a2+=$row["a0_1"]+$row["a0_2"]+$row["a0_3"]+$row["a1_1"]+$row["a1_2"]+$row["a1_3"];//留守儿童
						$p2+=$row["a0_1"]+$row["a0_2"]+$row["a0_3"]+$row["a1_1"]+$row["a1_2"]+$row["a1_3"];
						$a3+=$row["a2_0"]+$row["a3_0"];//住宿人数
						$p3+=$row["a2_0"]+$row["a3_0"];
					}
					$a4=round(($a2/$a1)*100)."%";
					$a5=round(($a3/$a1)*100)."%";
					
				}
				
				$zones[$k]["row"]=array($a1,$a2,$a4,$a3,$a5);
				$p4=round(($p2/$p1)*100)."%";
				$p5=round(($p3/$p1)*100)."%";
			}
		
			$total_ary=array($p1,$p2,$p4,$p3,$p5);

			$this->total=$total_ary;
			$this->zones = $zones;
			
			$this->total_schools=$this->tSchools->findAll();
      $this->display('map.html');
    }
	
	function export()
	{
		$this->display("export_index.html");
	}
    
		
		function return_day($i){
			if($i==1 || $i==3|| $i==5|| $i==7|| $i==8 || $i==10|| $i==12){
							$day=31;
				}else if($i==2){
					if($year%4==0 && $year%100!=0 ){
						$day=29;
					}else{
						$day=28;
					}
				}else{
					$day=30;
				}
				return $day;
		}
    
		function return_month($k){
			switch($k){
				case 1: return '一月';
				break;
				case 2:return '二月';
				break;
				case 3:return '三月';
				break;
				case 4:return '四月';
				break;
				case 5:return '五月';
				break;
				case 6:return '六月';
				break;
				case 7:return '七月';
				break;
				case 8:return '八月';
				break;
				case 9:return '九月';
				break;
				case 10:return '十月';
				break;
				case 11:return '十一月';
				break;
				case 12:return '十二月';
				break;
				
			}
		}
		
		function month_ary($cfrom,$cto){
			$s_time=date( "m",strtotime($cfrom));
			$s_year=date("Y",strtotime($cfrom));
			$e_time=date( "m",strtotime($cto));
			$e_year=date('Y',strtotime($cto));
			$ary_col=array();// 显示列的月数
			$ary_row=array();
				if($s_year!=$e_year){
					$col_end=12+$e_time;
				}else{
					$col_end=$e_time;
				}

				$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
				for($k=$s_time;$k<=$col_end;$k++){
				
					$ary_col[]=$k;
					
				}//endforeach
				
				return $ary_col;
		}
		
		
	 /*
		*
		*type=0 以天数为被除数*
		*type=1 以人数为被除数*
		*/
		
	 function addmonth($month,$ary_list,$type=0){
			$ti=0;
			$ci=0;
			$s_total=0;
			$no_total=0;
			
			for($i=0;$i<count($ary_list);$i++){
				
				$t_row=$ary_list[$i];
				foreach($t_row as $row){
					if($row){
						if($month==$row["month"]){
							
							if($type==1){
								$ti+=$row['tian'];
								$s_total+=$row["sum_ren"];
								$n_total+=$row["no_ren"];
								$total_pe=($s_total+$n_total);
							}else{
								$ti+=$row['tian'];
								$ci+=$row["cishu"]?$row["cishu"]:$row["xiaolu"];
							}
						}
					}//endif
					
				}//endforeach
			
			}//endfor
		
			return array('ci'=>$ci?$ci:'','ti'=>$ti?$ti:'','s_total'=>$s_total?$s_total:'','n_total'=>$n_total?$n_total:'','total_pe'=>$total_pe?$total_pe:'');
		}
		
		
		function getWeekName($data,$format = '星期')
		{
			
			$week   =  date( "D ",strtotime($data));
			$current="";
			switch($week)
			{
				case "Mon ":
					$current   =   $format."一";
					break;
				case "Tue ":
					$current   =   $format."二";
					break;
				case "Wed ":
					$current   =   $format."三";
					break;
				case "Thu ":
					$current   =   $format."四";
					break;
				case "Fri ":
					$current   =   $format."五";
					break;
				case "Sat ":
					$current   =   $format."六";
					break;
				case "Sun ":
					$current   =   $format."日";
					break;
			}
			return $current;
		}
		
		function addSong($str,$ary_songs){
			if($str!=""){
				if($ary_songs){
					$num = 0;
					foreach($ary_songs as $key=>$song){
						if(trim($str)==trim($song["name"])){
							$num = 1;
							$song["num"] = $song["num"] + 1;
							$ary_songs[$key]=array('num'=>$song["num"],'name'=>$song['name'],"sort"=>0);
						}
					}//endforeach
					
					if($num == 0){
						$ary_songs[]=array('num'=>1,'name'=>$str,"sort"=>0);
					}
					
				}else{
					$ary_songs[]=array('num'=>1,'name'=>$str,"sort"=>0);
				}//endif
			}//endif

		
			return $ary_songs;
		}
		
		
		
    function A01B()
    {

			 /*
			 * $schoolid
			 * termid
			 *
			 */
			
        $schoolid = $this->schoolid;    //取当前学校ID
        //取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
        $termid = $this->spArgs('termid', 1);//默认第一学期
        $this->termid = $termid;   
				
        /********下面开始处理数据库的数据***************/
				$sql_classes="select * from classes where schoolid=$schoolid ";
				$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
				
				foreach($ary_classes as $item){
					$ary_classid[]=$item["id"];
				}//本校所有的班id 
				
			
				$sql_terms="select * from terms where id =$termid ";
				$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
				$cfrom=$ary_terms[0]['cfrom'];
				$cto=$ary_terms[0]['cto'];
			
				$s_time=date( "m",strtotime($cfrom));
				$s_year=date("Y",strtotime($cfrom));
				$e_time=date( "m",strtotime($cto));
				$e_year=date('Y',strtotime($cto));
				$ary_col=array();// 显示列的月数
				$ary_row=array();
				if($s_year!=$e_year){
					$col_end=12+$e_time;
				}else{
					$col_end=$e_time;
				}

				$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
				for($k=$s_time;$k<=$col_end;$k++){
					if($k<=12){
						$ary_col[]=$this->return_month($k);
					}else{
						
						$s=$k-12;
						$ary_col[]=$this->return_month($s);
					}
					
				}
				$this->this_col=$ary_col;
								
				$ary_list=array();
				
				foreach($ary_classid as $ary){//循环班级
					$start=0;
					$end=0;
					$ary_month=array();
					
					if($s_year!=$e_year){
						$start=$s_time;
						$end=12+$e_time;
						$year=date("Y",strtotime($cfrom));
					}else{
						
						$start=$s_time;
						$end=$e_time;
						$year=date("Y",strtotime($cfrom));
					}
					
					$temp=0;
					
					for($i=$start;$i<=$end;$i++){//循环月份
				
						$temp=$i;
						
						if($i>12){
								$i=$i-12;
								
								$start_time=$e_year."-".$i."-"."1";
								if($e_time==$i){
									
									$end_time=$cto;
									
								}else{
									$day=$this->return_day($i);
									$end_time=$e_year."-".$i."-".$day;
								}
							}else{
							
								 $day=$this->return_day($i);
									$end_time=$year."-".$i."-".$day;
									if($i==$s_time){
										$start_time=$cfrom;
									}else{
										$start_time=$year."-".$i."-"."1";
									}
								
						  }
						
						$sql="select aa0, aa1, aa2 ,aa3, aa4, aa5, aa6, aa7, aa8 from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
					
							$num=0;//次数
							$tian=0;//天数
							$ary_month=$this->db->findSql($sql);
							
							if($ary_month){
								
								//$tian=0;
								foreach($ary_month as $item){
									
									if($item["aa0"]!="" || $item["aa1"]!="" ||$item["aa2"]!="" ||$item["aa3"]!="" ||$item["aa4"]!="" ||$item["aa5"]!="" ||$item["aa6"]!="" ||$item["aa7"]!="" || $item["aa8"]!="" ){
									
										$tian++;
									}
									
									foreach($item as $tt){
										if($tt){
											$num++;
										}
									}
						
								}//endforeach
								
								$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','classid'=>$ary,'month'=>$i);	
							}else{
								
								$ary_list[]="";
								
							}//endif ary_month
							
						$i=$temp;		
					}//endforeach
					
					$class_name="";
					foreach($ary_classes as $item){
						if($ary==$item["id"]){
							$class_name=$item["classname"];
						}
					}
					
					$total=0;
					$sum=0;
					$month=0;
					
					foreach($ary_list as $item){
						
						if($item){
							$total+=$item["cishu"];
							$sum+=$item["tian"];
							$month=$item["month"];
						}
						
					}
					
					if(!$sum || !$total){
						$sum="";
						$total="";
					}
					$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
					
					$ary_total=array();
					
					foreach($ary_list as $item){
						
						if($item){
							$total+=$item["cishu"];
							$sum+=$item["tian"];
							$month=$item["month"];
						}
						
					}
					
					$ary_row[]=array($class_name,$ary_list);
					$total_row=array();
				
					$ary_list="";
				}
				
					$ary_rows=array();
					foreach($ary_row as $item){
						$ary_rows[]=$item[1];
					}
				
			//total row
			for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
				if($r>12){
					$s=$r-12;
				}else{
					$s=$r;
				}
					
				$ary_total[]=$this->addmonth($s,$ary_rows);
			}
			
			$ary_total[]=$this->addmonth("total",$ary_rows);
			
		
				$this->tab_col=$ary_col;
				$this->lists=$ary_row;
				$this->total_row=$ary_total;
        $this->display('tables/A01B.html');

    }
		
		
		
		
	function A01C(){
	/*A01C 唱红歌汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		$this->this_col=$ary_col;
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
				
				$sql="select aa0, aa1, aa2 ,aa3, aa4, aa5, aa6, aa7, aa8 from class_statistics_each_day where classid in (select id from classes where schoolid=$school_id  ) and cdate>='$start_time' and cdate<='$end_time '";
				
			
					$num;//次数
					$ary_month=$this->db->findSql($sql);
					//$tian=count($ary_month);//天数
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							foreach($item as $tt){
								if($tt){
									$num++;
								}
							}
						
							if($item["aa0"]!="" || $item["aa1"]!="" ||$item["aa2"]!="" ||$item["aa3"]!="" ||$item["aa4"]!="" ||$item["aa5"]!="" ||$item["aa6"]!="" ||$item["aa7"]!="" || $item["aa8"]!="" ){
							
								$tian++;
								
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','classid'=>$ary,'month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A01C.html');

		 
	}
    

   

	function A01D()
	{
			
	 /*校内红歌排行榜
	 * $schoolid
	 * termid
	 *
	 */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		
		 /********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
		//echo "<pre>";
		//print_r($ary_classid);
	
		$total_songs=array();
				
		foreach($ary_classid as $ary){
			$sql="select aa0, aa1, aa2 ,aa3, aa4, aa5, aa6, aa7, aa8 from class_statistics_each_day where cdate>='$cfrom' and cdate<='$cto' and classid= ".$ary ;
			
			$ary_rows=$this->db->findSql($sql);
		
		
			if($ary_rows){
				foreach($ary_rows as $row){
					
					if($row["aa0"]){
						$total_songs=$this->addSong($row["aa0"],$total_songs);
					}
					
					if($row["aa1"]){
						$total_songs=$this->addSong($row["aa1"],$total_songs);
					}
					
					if($row["aa2"]){
						$total_songs=$this->addSong($row["aa2"],$total_songs);
					}
					
					if($row["aa3"]){
						$total_songs=$this->addSong($row["aa3"],$total_songs);
					}
					
					if($row["aa4"]){
						$total_songs=$this->addSong($row["aa4"],$total_songs);
					}
					
					if($row["aa5"]){
						$total_songs=$this->addSong($row["aa5"],$total_songs);
					}
					
					if($row["aa6"]){
						$total_songs=$this->addSong($row["aa6"],$total_songs);
					}
					
					if($row["aa7"]){
						$total_songs=$this->addSong($row["aa7"],$total_songs);
					}
					
					if($row["aa8"]){
						$total_songs=$this->addSong($row["aa8"],$total_songs);
					}
					
				}//endforeach
			
			}//endif
			
		}//endforeach_class
				
		rsort($total_songs);

		foreach($total_songs as $key=>$row){
		
			$sort=($key+1);
			
			$total_songs[$key] = array("num"=>$row["num"],"name"=>$row['name'],"sort"=>$sort);
		}
		

			$this->songs_list=$total_songs;
			
			$this->display('tables/A01D.html');
	}
	
	
	
	function  A01E(){
				
	 /*校内红歌排行榜
	 * $schoolid
	 * termid
	 *
	 */
		
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$schoolid="";
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		
		/********下面开始处理数据库的数据***************/
		if($schoolid){
			$sql_classes="select * from classes where schoolid=$schoolid ";
		}else{
			$sql_classes="select * from classes ";
		}
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
	
		$total_songs=array();
				
		foreach($ary_classid as $ary){
			if($cfrom!="" && $cto!=""){
				$sql="select aa0, aa1, aa2 ,aa3, aa4, aa5, aa6, aa7, aa8 from class_statistics_each_day where  cdate>='$cfrom' and cdate<='$cto' and classid= ".$ary ;
			}else{
				$sql="select aa0, aa1, aa2 ,aa3, aa4, aa5, aa6, aa7, aa8 from class_statistics_each_day where classid= ".$ary ;
			}
			
			$ary_rows=$this->db->findSql($sql);
			if($ary_rows){
				foreach($ary_rows as $row){
					
					if($row["aa0"]){
						$total_songs=$this->addSong($row["aa0"],$total_songs);
					}
					
					if($row["aa1"]){
						$total_songs=$this->addSong($row["aa1"],$total_songs);
					}
					
					if($row["aa2"]){
						$total_songs=$this->addSong($row["aa2"],$total_songs);
					}
					
					if($row["aa3"]){
						$total_songs=$this->addSong($row["aa3"],$total_songs);
					}
					
					if($row["aa4"]){
						$total_songs=$this->addSong($row["aa4"],$total_songs);
					}
					
					if($row["aa5"]){
						$total_songs=$this->addSong($row["aa5"],$total_songs);
					}
					
					if($row["aa6"]){
						$total_songs=$this->addSong($row["aa6"],$total_songs);
					}
					
					if($row["aa7"]){
						$total_songs=$this->addSong($row["aa7"],$total_songs);
					}
					
					if($row["aa8"]){
						$total_songs=$this->addSong($row["aa8"],$total_songs);
					}
					
				}//endforeach
			
			}//endif
			
		}//endforeach_class
				
		rsort($total_songs);

		foreach($total_songs as $key=>$row){
		
			$sort=($key+1);
			
			$total_songs[$key] = array("num"=>$row["num"],"name"=>$row['name'],"sort"=>$sort);
		}
		

			$this->songs_list=$total_songs;
			
			$this->display('tables/A01E.html');
	}
	
	
    
	function A03B(){
	/*
	 * $schoolid
	 * termid
	 *
	 */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		$sql="select  cdate,a0,a2,a4,a6,a1,a3,a5,a7  from school_statistics_each_week_3 where schoolid=$schoolid and cdate>='$cfrom' and cdate<='$cto'";
		$ary_list=$this->db->findSql($sql);
		
		$this->ary_list=$ary_list;
		
		$this->display('tables/A03B.html');
	}
	
	
	
	function A03C(){
		
	/*A03C 各学校升国旗汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
					$sql="select  cdate,a0,a2,a4,a6,a1,a3,a5,a7  from school_statistics_each_week_3 where schoolid=$school_id and cdate>='$start_time' and cdate<='$end_time'";

				
			
					$num;//次数
					$ary_month=$this->db->findSql($sql);
					//$tian=count($ary_month);//天数
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						foreach($ary_month as $item){
					
							$num+=$item["a5"];
						
						if($item["a0"]!="" || $item["a1"]!="" ||$item["a2"]!="" ||$item["a3"]!="" ||$item["a4"]!="" ||$item["a5"]!="" ||$item["a6"]!="" ||$item["a7"]!="" ){
								$tian++;
							}
							
						}//endforeach
						
						
						
						$ary_list[]=array('cishu'=>$num,'tian'=>$tian,'classid'=>$ary,'month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A03C.html');

		 
		
	}
	
	
	/*****************************************************************/
	function A06B(){
				
	/*
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
						
						$sql="select * from actions where schoolid=$school_id and cdate>='$start_time' and cdate<='$end_time' and r1=3 ";

					$num;//次数
					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							if($item){
								
								if($item["r3"]!=""){
									$num+=1;
								}
							
								$total+=$tian;
								$sum+=$num;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
		
			$ary_list[]=array('cishu'=>$total?$total:'','tian'=>$sum?$sum:'','classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A06B.html');
	}
	
	
	
	function A10B(){
		/*广播站\电视台统计表
		 * $schoolid
		 * termid
		 *
		 */
		 
			$schoolid = $this->schoolid;    //取当前学校ID
			//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
			$termid = $this->spArgs('termid', 1);//默认第一学期
			$this->termid = $termid;  
			$sql_terms="select * from terms where id =$termid ";
			$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
			$cfrom=$ary_terms[0]['cfrom'];
			$cto=$ary_terms[0]['cto'];
			
			$ary=$this->month_ary($cfrom,$cto);//得到月份
			$s_year=date("Y",strtotime($cfrom));
			$e_year=date("Y",strtotime($cto));
			
			$ary_row=array();
			$total=0;
			$sum=0;
				
			foreach($ary as $key=>$item){
				if($item>12){
					$ary[$key]=$item-12;
					$year=$e_year;
					$item=$item-12;
					
				}else{
					$year=$s_year;
				}
				$s_time=$year."-".$item."-"."1";
				$day=$this->return_day($item);
				$s_end=$year."-".$item."-".$day;
				$ary_col[]=$this->return_month($item);
				
				$a1=$a2=0;
				$sql="select a0_1_1,a0_1_2  from school_statistics_each_month where cdate>='$s_time' and cdate<='$s_end'  and schoolid=$schoolid";
				$ary_terms=$this->db->findSql($sql);
				
				foreach($ary_terms as $row){
					if($row){
						if($row["a0_1_1"]!=""){
							$a1+=$row["a0_1_1"];
						}
						if($row["a0_1_2"]!=""){
							$a2+=$row["a0_1_2"];
						}
						$total+=$a1;
						$sum+=$a2;
						
					}
				}
				$ary_list[]=array("ren"=>$a1,"ci"=>$a2);
				
			}//endforeach
			
			$ary_col[count($ary_col)]="小计";
			$this->month_ary=$ary_col;
		
			array_push($ary_list,array("ren"=>$total,"ci"=>$sum));
			$this->ary_list=$ary_list;
			
			$this->display('tables/A10B.html');
	}
	
	
	function A10C(){
		
	/*A10C 各学校广播站、电视台汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
						$sql="select a0_1_1,a0_1_2  from school_statistics_each_month where cdate>='$start_time' and cdate<='$end_time'  and schoolid=$school_id";

					$num;//次数
					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							if($item){
								if($item["a0_1_1"]!=""){
									$tian+=$item["a0_1_1"];
								}
								if($item["a0_1_2"]!=""){
									$num+=$item["a0_1_2"];
								}
							
								$total+=$tian;
								$sum+=$num;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A10C.html');
		
	}
	
	
	
	function A04B(){
		/*A04B读经典统计
		 * $schoolid
		 * termid
		 *
		 */
		 
		 $schoolid = $this->schoolid;    //取当前学校ID
        //取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
        $termid = $this->spArgs('termid', 1);//默认第一学期
        $this->termid = $termid;   
				
        /********下面开始处理数据库的数据***************/
				$sql_classes="select * from classes where schoolid=$schoolid ";
				$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
				
				foreach($ary_classes as $item){
					$ary_classid[]=$item["id"];
				}//本校所有的班id 
				
			
				$sql_terms="select * from terms where id =$termid ";
				$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
				$cfrom=$ary_terms[0]['cfrom'];
				$cto=$ary_terms[0]['cto'];
			
				$s_time=date( "m",strtotime($cfrom));
				$s_year=date("Y",strtotime($cfrom));
				$e_time=date( "m",strtotime($cto));
				$e_year=date('Y',strtotime($cto));
				$ary_col=array();// 显示列的月数
				$ary_row=array();
				if($s_year!=$e_year){
					$col_end=12+$e_time;
				}else{
					$col_end=$e_time;
				}

				$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
				for($k=$s_time;$k<=$col_end;$k++){
					if($k<=12){
						$ary_col[]=$this->return_month($k);
					}else{
						
						$s=$k-12;
						$ary_col[]=$this->return_month($s);
					}
					
				}
				$this->this_col=$ary_col;
								
				$ary_list=array();
				
				foreach($ary_classid as $ary){//循环班级
					$start=0;
					$end=0;
					$ary_month=array();
					
					if($s_year!=$e_year){
						$start=$s_time;
						$end=12+$e_time;
						//echo "endtime===".$end."<br>";
						$year=date("Y",strtotime($cfrom));
						
						
					}else{
						
						$start=$s_time;
						$end=$e_time;
						$year=date("Y",strtotime($cfrom));
					}
				
				
				//	echo $e_time;
					$temp=0;
					
					for($i=$start;$i<=$end;$i++){//循环月份
				
						$temp=$i;
						
						if($i>12){
								$i=$i-12;
								
								$start_time=$e_year."-".$i."-"."1";
								if($e_time==$i){
									
									$end_time=$cto;
									
								}else{
									$day=$this->return_day($i);
									$end_time=$e_year."-".$i."-".$day;
								}
							}else{
							
								 $day=$this->return_day($i);
									$end_time=$year."-".$i."-".$day;
									if($i==$s_time){
										$start_time=$cfrom;
									}else{
										$start_time=$year."-".$i."-"."1";
									}
								
						  }
						
						$sql="select ab0,classid from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
					
							$num;//次数
							$ary_month=$this->db->findSql($sql);
							$tian=count($ary_month);//天数
							
							
							if($ary_month){
								$num=0;
								$tian=0;
								foreach($ary_month as $item){
									
									if($item["ab0"]!=""){
										$tian+=1;
										$num+=$item["ab0"];
									}
									
								}//endforeach
								
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','classid'=>$ary,'month'=>$i);	
						
							}else{
								
								$ary_list[]="";
								
							}//endif ary_month
							
						$i=$temp;		
						
								
					}//endforeach
					
					$class_name="";
					foreach($ary_classes as $item){
						if($ary==$item["id"]){
							$class_name=$item["classname"];
						}
					}
					
					$total=0;
					$sum=0;
					$month=0;
					
					
					foreach($ary_list as $item){
						
						if($item){
							$total+=$item["cishu"];
							$sum+=$item["tian"];
							$month=$item["month"];
						}
						
					}
					
					if(!$sum || !$total){
						$sum="";
						$total="";
					}
					$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
					
					$ary_total=array();
					
					foreach($ary_list as $item){
						
						if($item){
							$total+=$item["cishu"];
							$sum+=$item["tian"];
							$month=$item["month"];
						}
						
					}
					
					$ary_row[]=array($class_name,$ary_list);
					$total_row=array();
				
					$ary_list="";
				}
				
					$ary_rows=array();
					foreach($ary_row as $item){
						$ary_rows[]=$item[1];
					}
				
			//total row
			for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
				if($r>12){
					$s=$r-12;
				}else{
					$s=$r;
				}
					
				$ary_total[]=$this->addmonth($s,$ary_rows);
			}
			
			$ary_total[]=$this->addmonth("total",$ary_rows);
			
		
				$this->tab_col=$ary_col;
				$this->lists=$ary_row;
				$this->total_row=$ary_total;
        $this->display('tables/A04B.html');

		 
		 //A04B
	}
	
	
	
	function A04C(){
		
	/*A04C 读经典汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
						$sql="select ab0 from class_statistics_each_day where classid in(select id from classes where schoolid=$school_id  ) and cdate>='$start_time' and cdate<='$end_time '";

				
			
					$num;//次数
					$ary_month=$this->db->findSql($sql);
					//$tian=count($ary_month);//天数
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							if($item["ab0"]!=""){
										$tian+=1;
										$num+=$item["ab0"];
							}
						
							
						}//endforeach
						
						
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','classid'=>$ary,'month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A04C.html');

	}
	
	
	
	function A06A(){
		/*A06A红色电影统计表
		 * $schoolid
		 * termid
		 *
		 */
			
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		
		$sql="select * from actions where schoolid=$schoolid and cdate>='$cfrom' and cdate<='$cto' and r1=3 ";
		$ary_list=$this->db->findSql($sql);
		if($ary_list){
			foreach($ary_list as $key=>$item){
				
				$ary_list[$key]=array("id"=>$item["id"],"cdate"=>$item["cdate"],"r4"=>$item["r4"],"r5"=>$item["r5"],"theme"=>$item["theme"],"r3"=>$item["r3"]);
			
			}
		}
		
		$this->ary_list=$ary_list;
				
		$this->display('tables/A06A.html');
	}
	
	
	
	function A07B(){
		
		/*A07B讲故事统计表
		 * $schoolid
		 * termid
		 *
		 */
 
 		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		$this->this_col=$ary_col;
						
		$ary_list=array();
		
		foreach($ary_classid as $ary){//循环班级
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				//echo "endtime===".$end."<br>";
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
		//	echo $e_time;
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
				
				$sql="select ab1 from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
			
					$num;//次数
					$ary_month=$this->db->findSql($sql);
					$tian=count($ary_month);//天数
					
					
					if($ary_month){
						$num=0;
						$tian=0;
						foreach($ary_month as $item){
							
							if($item["ab1"]!=""){
								$tian+=1;
								$num+=$item["ab1"];
							}
							
						}//endforeach
						
						
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','classid'=>$ary,'month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
						
			}//endforeach
			
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($class_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A07B.html');

	}
	
	
	
	
	function  A07C(){
	/*A07C 讲故事汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
				$sql="select ab1 from class_statistics_each_day where classid in(select id from  classes where schoolid=$school_id) and cdate>='$start_time' and cdate<='$end_time' ";


					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							if($item){
								
								if($item["ab1"]!=""){
									$tian+=1;
									$num+=$item["ab1"];
								}
								$total+=$tian;
								$sum+=$num;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A07C.html');
	}
	
	
	
	function A09B(){
		
		/*A09C班级传箴言统计表
		 * $schoolid
		 * termid
		 *
		 */
 
 		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		$this->this_col=$ary_col;
						
		$ary_list=array();
		
		foreach($ary_classid as $ary){//循环班级
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				//echo "endtime===".$end."<br>";
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
		//	echo $e_time;
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
				
				$sql="select ab2 from class_statistics_each_day  where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
			
					$num;//次数
					$ary_month=$this->db->findSql($sql);
					$tian=count($ary_month);//天数
					
					
					if($ary_month){
						$num=0;
						$tian=0;
						foreach($ary_month as $item){
							
						
							if($item["ab2"]!=""){
								$tian+=1;
								$num=$item["ab2"];
							}
							
						}//endforeach
						
						
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','classid'=>$ary,'month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
						
			}//endforeach
			
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($class_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A09B.html');

	}
	
	
	
	function A09D(){
		
		/*A09C学校传箴言统计表
		 * $schoolid
		 * termid
		 *
		 */
 
 		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		$this->this_col=$ary_col;
						
		$ary_list=array();
		
		foreach($ary_classid as $ary){//循环班级
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				//echo "endtime===".$end."<br>";
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
		//	echo $e_time;
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
				
				$sql="select a0_2 from school_statistics_each_month where schoolid= ".$schoolid ." and cdate>='$start_time' and cdate<='$end_time '";
			
					$num;//次数
					$ary_month=$this->db->findSql($sql);
					$tian=count($ary_month);//天数
					
					
					if($ary_month){
						$num=0;
						$tian=0;
						foreach($ary_month as $item){
							
							
							if($item["a0_2"]!=""){
								$tian+=1;
								$num=$item["a0_2"];
							}
							
						}//endforeach
						
						
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','classid'=>$ary,'month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
						
			}//endforeach
			
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($class_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
  $a_num=count($ary_row);
		foreach($ary_total as $key=>$aitem){
			if($aitem["ci"]!=""){
				
				$ary_total[$key]=array("ci"=>$aitem["ci"]/$a_num,"ti"=>$aitem["ti"]/$a_num);
			}
			
		}

		$this->tab_col=$ary_col;
		//$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A09D.html');

	}
	
	
	
	function A09E(){
		
	/*A09E 传箴言汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
					//$sql="select * from actions where schoolid=$school_id and cdate>='$start_time' and cdate<='$end_time' and r1=3 ";
					
					
				$sql="select a0_2 from school_statistics_each_month where schoolid= ".$school_id ." and cdate>='$start_time' and cdate<='$end_time '";


					$num;//次数
					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							if($item){
								
								if($item["a0_2"]!=""){
									$tian+=1;
									$num+=$item["a0_2"];
								}
								$total+=$tian;
								$sum+=$num;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/A09E.html');
	}
	
	
	
	function B01A(){
		/*情景模拟统计表
		 * $schoolid
		 * termid
		 *
		 */
			
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		
		$sql="select * from actions where schoolid=$schoolid and cdate>='$cfrom' and cdate<='$cto' and r1=7 ";
		$ary_list=$this->db->findSql($sql);
		if($ary_list){
			foreach($ary_list as $key=>$item){
				//$innr_sql="select * from super_config01 where id=".$item["r3"];
				//$value=$this->db->findSql($innr_sql);
				//$r=$value[0]['value'];
				$ary_list[$key]=array("id"=>$item["id"],"cdate"=>$item["cdate"],"r4"=>$item["r4"],"r5"=>$item["r5"],"theme"=>$item["theme"],"r3"=>$item["r3"],"fullPath"=>$item["fullPath"]);
			
			}
		}
		
		$this->ary_list=$ary_list;
				
		$this->display('tables/B01A.html');
	}
	
	
	
	function B01B(){
		
	/*B01B 各学校情景模拟汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			

				$sql="select * from actions where schoolid=$school_id and cdate>='$start_time' and cdate<='$end_time' and r1=7 ";

					$num;//次数
					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							if($item){
								
								if($item["r1"]!=""){
									$num+=1;
								}
								$total+=$tian;
								$sum+=$num;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
	
			$ary_list[]=array('cishu'=>$total?$total:'','tian'=>$sum?$sum:'','classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/B01B.html');
		//B01B 各学校情景模拟汇总表
	}
	
	
	function B02B(){
		/*B02B课外兴趣小组统计表
		 * $schoolid
		 * termid
		 *
		 */
		 
			$schoolid = $this->schoolid;    //取当前学校ID
			//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
			$termid = $this->spArgs('termid', 1);//默认第一学期
			$this->termid = $termid;  
			$sql_terms="select * from terms where id =$termid ";
			$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
			$cfrom=$ary_terms[0]['cfrom'];
			$cto=$ary_terms[0]['cto'];
			
			$ary=$this->month_ary($cfrom,$cto);//得到月份
			$s_year=date("Y",strtotime($cfrom));
			$e_year=date("Y",strtotime($cto));
			
			$ary_row=array();
			$total=0;
			$sum=0;
				
			foreach($ary as $key=>$item){
				if($item>12){
					$ary[$key]=$item-12;
					$year=$e_year;
					$item=$item-12;
					
				}else{
					$year=$s_year;
				}
				$s_time=$year."-".$item."-"."1";
				$day=$this->return_day($item);
				$s_end=$year."-".$item."-".$day;
				$ary_col[]=$this->return_month($item);
				
				$a1=$a2=0;
				$sql="select b0_1,b0_2  from school_statistics_each_month where cdate>='$s_time' and cdate<='$s_end'  and schoolid=$schoolid";
				$ary_terms=$this->db->findSql($sql);
				
				foreach($ary_terms as $row){
					if($row){
						if($row["b0_1"]!=""){
							$a1+=$row["b0_1"];
						}
						if($row["b0_2"]!=""){
							$a2+=$row["b0_2"];
						}
						$total+=$a1;
						$sum+=$a2;
						
					}
				}
				$ary_list[]=array("ren"=>$a1?$a1:'',"ci"=>$a2?$a2:'');
				
			}//endforeach
			
			$ary_col[count($ary_col)]="小计";
			$this->month_ary=$ary_col;
		
			array_push($ary_list,array("ren"=>$total?$total:'',"ci"=>$sum?$sum:''));
			$this->ary_list=$ary_list;
		
		$this->display('tables/B02B.html');
	}
	
	
	
	function B02C(){
		
		$this->display('tables/B02C.html');
	}
	
	
	function B04B(){
	 /*	D04B学生洗浴统计表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
				
		$this->this_col=$ary_col;//表头月份
		
		foreach($ary_classid as $ary){//循环班级得到每月统计记录
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));

			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
		$temp=$inner=$pk=0;
		for($i=$start;$i<=$end;$i++){//循环月份
		
		$pk++;
		$temp=$i;
		
		if($i>12){
				$i=$i-12;
				
				$start_time=$e_year."-".$i."-"."1";
				if($e_time==$i){
					
					$end_time=$cto;
					
				}else{
					$day=$this->return_day($i);
					$end_time=$e_year."-".$i."-".$day;
				}
			}else{
			
				 $day=$this->return_day($i);
					$end_time=$year."-".$i."-".$day;
					if($i==$s_time){
						$start_time=$cfrom;
					}else{
						$start_time=$year."-".$i."-"."1";
					}
				
			}
				
				$add_ary;
			
				$sql="select b0, b1,classid  from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
				
				$str_sql="select a0_0,a1_0 from class_statistics_each_term where classid=$ary and termid=$termid";//每班人数

				$peo_ary=$this->db->findSql($str_sql);
			
				$c1=$c2=$c3=0;
				if($peo_ary){
					$c1=$peo_ary[0]['a0_0']?$peo_ary[0]['a0_0']:'';
					$c2=$peo_ary[0]['a1_0']?$peo_ary[0]['a1_0']:'';
					$c3=$c1+$c2;
					$add_ary=array('classid'=>$ary,'month'=>'pe_sum','total_pe'=>$c3?$c3:'','sum_ren'=>$c1,'no_ren'=>$c2);	
			
				}else{
					$c3=0;
					$add_ary="";
				}
					
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_pe=0;
						foreach($ary_month as $item){
							
							if($item["b0"]){
								$a1+=$item["b0"];//本数
							}
							if($item["b1"]){
								$a2+=$item["b1"];//字数
							}
						
							$s_pe+=($a1+$a2);//小计
						}
						
						if(!$a1){
							$a1="";
						}
						
						if(!$a2){
							$a2="";
						}
	
						$total_pe=$s_pe?$s_pe:'';//当前月洗浴次数
		
						$ary_list[]=array('classid'=>$ary,'month'=>$i,'total_pe'=>$total_pe,'sum_ren'=>$a1,'no_ren'=>round($a2/1000)?round($a2/1000):'');	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
			
			}//endforeach
			
			
			//取得班级名称
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"]?$item["sum_ren"]:"";//本数
					$n_total+=$item["no_ren"]?$item["no_ren"]:"";//字数
					$month=$item["month"];
					$sum+=$item["total_pe"];
				}
			}
			
			$xi=0;
			
			$ary_list[]=array('classid'=>$ary,'month'=>'total','xiaolu'=>$xi,'total_pe'=>$sum?$sum:'',"sum_ren"=>$s_total?$s_total:'',"no_ren"=>$n_total?$n_total:'');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			$ary_row[]=array($class_name,$ary_list,$c3?$c3:'');
		
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
		foreach($ary_row as $pitem){
			$inner+=$pitem[2];
		}
		$this->add_t=$inner;//总人数
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){

				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100);
				$str['ci']=$xi;
				
			}
	
			$ary_total[]=$str;
		}
		
		$stt=$this->addmonth("total",$ary_rows,1);
		$ary_total[]=$stt;//小计底部总计
		
		
		$one_ary=$ary_total[0];
		$girl=$one_ary["n_total"];
		$boy=$one_ary["s_total"];
		$all=$one_ary["total_pe"];
		
		
		$last_ary=array();
		
		foreach($ary_total as $key=>$avg){
			$a_num=1;
			if($key==(count($ary_total)-1)){
				//$a_num=$pk;//月份数
			}
			
			$add_t=$inner;//总人数
			$s_boy=$avg["s_total"]/($add_t*$a_num)?$avg["s_total"]/($add_t*$a_num):'';
			$s_boy=round($s_boy,2);
			$n_girl=$avg["n_total"]/($add_t*$a_num)?$avg["n_total"]/($add_t*$a_num):'';
			$xx=round($n_girl,2);
		//	$s_all=round(($avg["total_pe"]/($all*$a_num))*100)?round(($avg["total_pe"]/($all*$a_num))*100):'';
			$last_ary[]=array("ci"=>'',"ti"=>'',"s_total"=>$s_boy?$s_boy:'',"n_total"=>$xx?$xx:'');
		}
	

		$this->str_name="总计";
		$this->str_name2="人均";
		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
	
		$this->avg_row=$last_ary;
			
		$this->display('tables/B04B.html');
	}
	
	
	
	function B04C(){
	 /*	B04C 各学校阅读提升汇总表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_schools="select * from schools ";
		$ary_schools=$this->db->findSql($sql_schools);//得到学校下的班级
		

	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
				
		$this->this_col=$ary_col;//表头月份
		
		foreach($ary_schools as $ary){//循环学校得到每个学校的记录
			$school_id=$ary["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));

			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
		$temp=$inner=$pk=0;
		for($i=$start;$i<=$end;$i++){//循环月份
		
		$pk++;
		$temp=$i;
		
		if($i>12){
				$i=$i-12;
				
				$start_time=$e_year."-".$i."-"."1";
				if($e_time==$i){
					
					$end_time=$cto;
					
				}else{
					$day=$this->return_day($i);
					$end_time=$e_year."-".$i."-".$day;
				}
			}else{
			
				 $day=$this->return_day($i);
					$end_time=$year."-".$i."-".$day;
					if($i==$s_time){
						$start_time=$cfrom;
					}else{
						$start_time=$year."-".$i."-"."1";
					}
				
			}
				
				$add_ary;
			
				$sql="select b0, b1,classid  from class_statistics_each_day where classid in(select id from classes where schoolid=$school_id) and cdate>='$start_time' and cdate<='$end_time '";
				
				$str_sql="select a0_0,a1_0 from class_statistics_each_term where classid in(select id  from classes where schoolid=$school_id) and termid=$termid";//每班人数
			
				$peo_ary=$this->db->findSql($str_sql);

				$c1=$c2=$c3=0;
				if($peo_ary){
					foreach($peo_ary as $ar){
						$c1+=$ar['a0_0']?$ar['a0_0']:'';
						$c2+=$ar['a1_0']?$ar['a1_0']:'';
						$c3+=$ar['a0_0']+$ar['a1_0'];
					}
					$add_ary=array('month'=>'pe_sum','total_pe'=>$c3?$c3:'','sum_ren'=>$c1,'no_ren'=>$c2);	
				}else{
					$c3=0;
					$add_ary="";
				}
					
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_pe=0;
						foreach($ary_month as $item){
							
							if($item["b0"]){
								$a1+=$item["b0"];//本数
							}
							if($item["b1"]){
								$a2+=$item["b1"];//字数
							}
						
							$s_pe+=($a1+$a2);//小计
						}
						
						if(!$a1){
							$a1="";
						}
						
						if(!$a2){
							$a2="";
						}
	
						$total_pe=$s_pe?$s_pe:'';
		
						$ary_list[]=array('month'=>$i,'total_pe'=>$total_pe?$total_pe:'','sum_ren'=>$a1,'no_ren'=>round($a2/1000)?round($a2/1000):'');	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
			
			}//endforeach
			
			
			//取得班级名称
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"]?$item["sum_ren"]:"";//本数
					$n_total+=$item["no_ren"]?$item["no_ren"]:"";//字数
					$month=$item["month"];
					$sum+=$item["total_pe"];
				}
			}
			
			$xi=0;
			
			$ary_list[]=array('classid'=>$ary,'month'=>'total','xiaolu'=>$xi,'total_pe'=>$sum?$sum:'',"sum_ren"=>$s_total?$s_total:'',"no_ren"=>$n_total?$n_total:'');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			$ary_row[]=array($school_name,$ary_list,$c3?$c3:'');
		
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
		foreach($ary_row as $pitem){
			$inner+=$pitem[2];
		}
		$this->add_t=$inner;//总人数
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100);
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
		$stt=$this->addmonth("total",$ary_rows,1);
		$ary_total[]=$stt;//小计底部总计
		
		
		$one_ary=$ary_total[0];
		$girl=$one_ary["n_total"];
		$boy=$one_ary["s_total"];
		$all=$one_ary["total_pe"];
		
		
		$last_ary=array();
		foreach($ary_total as $key=>$avg){
			$a_num=1;
			if($key==(count($ary_total)-1)){
				$a_num=$pk;//月份数
			}
			
			$add_t=$inner;//总人数

			$s_boy=$avg["s_total"]/($add_t*$a_num)?$avg["s_total"]/($add_t*$a_num):'';
			$s_boy=round($s_boy,2);
			$s_boy=$s_boy<0.01?0:$s_boy;
			$n_girl=round($avg["n_total"]/($add_t*$a_num),2);
			if($s_boy==0 && $n_girl==0){
				$s_boy="";
				$n_girl="";
			}
		
			$last_ary[]=array("ci"=>'',"ti"=>'',"s_total"=>$s_boy,"n_total"=>$n_girl);
		}
	

		$this->str_name="总计";
		$this->str_name2="人均";
		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
		$this->avg_row=$last_ary;
			
		$this->display('tables/B04C.html');
	}
	
	
	
	
		function C01B(){
	 /*	C01B家纺统计表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
				
		$this->this_col=$ary_col;//表头月份
		
		foreach($ary_classid as $ary){//循环班级得到每月统计记录
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));

			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
		$temp=$inner=$pk=0;
		for($i=$start;$i<=$end;$i++){//循环月份
		
		$pk++;
		$temp=$i;
		
		if($i>12){
				$i=$i-12;
				
				$start_time=$e_year."-".$i."-"."1";
				if($e_time==$i){
					
					$end_time=$cto;
					
				}else{
					$day=$this->return_day($i);
					$end_time=$e_year."-".$i."-".$day;
				}
			}else{
			
				 $day=$this->return_day($i);
					$end_time=$year."-".$i."-".$day;
					if($i==$s_time){
						$start_time=$cfrom;
					}else{
						$start_time=$year."-".$i."-"."1";
					}
				
			}
				
				$add_ary;
			
				$sql="select cd1, cd2  from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
				
				$str_sql="select a0_0,a1_0 from class_statistics_each_term where classid=$ary and termid=$termid";//每班人数

				$peo_ary=$this->db->findSql($str_sql);
			
				$c1=$c2=$c3=0;
				if($peo_ary){
					$c1=$peo_ary[0]['a0_0']?$peo_ary[0]['a0_0']:'';
					$c2=$peo_ary[0]['a1_0']?$peo_ary[0]['a1_0']:'';
					$c3=$c1+$c2;
					$add_ary=array('classid'=>$ary,'month'=>'pe_sum','total_pe'=>$c3,'sum_ren'=>$c1,'no_ren'=>$c2);	
			
				}else{
					$c3=0;
					$add_ary="";
				}
					
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_pe=0;
						foreach($ary_month as $item){
							
							if($item["cd1"]){
								$a1+=$item["cd1"];//新访
							}
							if($item["cd2"]){
								$a2+=$item["cd2"];//回访
							}
						
							$s_pe+=($a1+$a2);//小计
						}
						
						if(!$a1){
							$a1="";
						}
						
						if(!$a2){
							$a2="";
						}
	
						$total_pe=$s_pe?$s_pe:'';//当前月洗浴次数
						
		
						$ary_list[]=array('classid'=>$ary,'month'=>$i,'total_pe'=>$total_pe,'sum_ren'=>$a1,'no_ren'=>$a2?$a2:'');	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
			
			}//endforeach
			
			
			//取得班级名称
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"]?$item["sum_ren"]:"";//新访
					$n_total+=$item["no_ren"]?$item["no_ren"]:"";//回访
					$month=$item["month"];
					$sum+=$item["total_pe"];
				}
			}
			
			$xi=0;
			
			$ary_list[]=array('classid'=>$ary,'month'=>'total','xiaolu'=>$xi,'total_pe'=>$sum?$sum:'',"sum_ren"=>$s_total?$s_total:'',"no_ren"=>$n_total?$n_total:'');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			$ary_row[]=array($class_name,$ary_list,$c3?$c3:'');
		
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
		foreach($ary_row as $pitem){
			$inner+=$pitem[2];
		}
		$this->add_t=$inner;//总人数
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100);
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
		$stt=$this->addmonth("total",$ary_rows,1);
		$ary_total[]=$stt;//小计底部总计	
				
		$one_ary=$ary_total[0];
		$girl=$one_ary["n_total"];
		$boy=$one_ary["s_total"];
		$all=$one_ary["total_pe"];
		
		
		$this->str_name="总计";
		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
			
		$this->display('tables/C01B.html');
		
		//12、	C01B家纺统计表
	}
	
	
	
	
	function C01C(){
		/*A09E 传箴言汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
		
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
					
									
				$add_ary;
			
				$sql="select cd1, cd2  from class_statistics_each_day where classid in(select id from classes where schoolid=$school_id) and cdate>='$start_time' and cdate<='$end_time '";
				
				$str_sql="select a0_0,a1_0 from class_statistics_each_term where classid in(select id from classes where schoolid=$school_id)  and termid=$termid";//每班人数

				$peo_ary=$this->db->findSql($str_sql);
			
				$c1=$c2=$c3=0;
				if($peo_ary){
					foreach($peo_ary as $ar){
						$c1+=$ar['a0_0']?$ar['a0_0']:'';
						$c2+=$ar['a1_0']?$ar['a1_0']:'';
						$c3+=$ar['a0_0']+$ar['a1_0'];
						$add_ary=array('month'=>'pe_sum','total_pe'=>$c3,'sum_ren'=>$c1,'no_ren'=>$c2);	
					}
				}else{
					$c3=0;
					$add_ary="";
				}


					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							if($item){
								
									$a1=$a2=$s_pe=0;
									foreach($ary_month as $item){
										
										if($item["cd1"]){
											$a1+=$item["cd1"];//新访
										}
										if($item["cd2"]){
											$a2+=$item["cd2"];//回访
										}
									
										$s_pe+=($a1+$a2);//小计
									}
									
									if(!$a1){
										$a1="";
									}
									
									if(!$a2){
										$a2="";
									}
				
									$total_pe=$s_pe?$s_pe:'';//当前月洗浴次数
									
					
								$total+=$a1;
								$sum+=$a2;
							}
							
						}//endforeach
						$ary_list[]=array('month'=>$i,'total_pe'=>$total_pe,'sum_ren'=>$a1,'no_ren'=>$a2?$a2:'');	

						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			

						
			foreach($ary_list as $item){

				if($item){

					$s_total+=$item["sum_ren"]?$item["sum_ren"]:"";//新访
					$n_total+=$item["no_ren"]?$item["no_ren"]:"";//回访
					$month=$item["month"];
					$sum+=$item["total_pe"];
				}
				
			}
			
			$xi=0;
			
			$ary_list[]=array('month'=>'total','xiaolu'=>$xi,'total_pe'=>$sum?$sum:'',"sum_ren"=>$s_total?$s_total:'',"no_ren"=>$n_total?$n_total:'');//添加小计
			
		
			$ary_total=array();
			$ary_row[]=array($school_name,$ary_list,$c3?$c3:'');
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
		foreach($ary_row as $pitem){
			$inner+=$pitem[2];
		}
		$this->add_t=$inner;//总人数
			

		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows,1);
	}

		
		
		$stt=$this->addmonth("total",$ary_rows,1);
		$ary_total[]=$stt;//小计底部总计	
				
		
		$this->str_name="总计";
		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计

		$this->display('tables/C01C.html');
	}
	
	
	
	
	function C06B(){
	 /*	C06B代理家长统计表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";

		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
				
		$this->this_col=$ary_col;//表头月份

		
		foreach($ary_classid as $ary){//循环班级得到每月统计记录
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));

			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
				

		
		$temp=$inner=$pk=0;
		for($i=$start;$i<=$end;$i++){//循环月份
			

		$pk++;
		$temp=$i;
		
		if($i>12){
				$i=$i-12;
				
				$start_time=$e_year."-".$i."-"."1";
				if($e_time==$i){
					
					$end_time=$cto;
					
				}else{
					$day=$this->return_day($i);
					$end_time=$e_year."-".$i."-".$day;
				}
			}else{
			
				 $day=$this->return_day($i);
					$end_time=$year."-".$i."-".$day;
					if($i==$s_time){
						$start_time=$cfrom;
					}else{
						$start_time=$year."-".$i."-"."1";
					}
				
			}
				
				$add_ary;
			
				$sql="select cd0 from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";

				
				$str_sql="select a0_0,a1_0 from class_statistics_each_term where classid=$ary and termid=$termid";//每班人数

				$peo_ary=$this->db->findSql($str_sql);
			
				$c1=$c2=$c3=0;
				if($peo_ary){
					$c1=$peo_ary[0]['a0_0']?$peo_ary[0]['a0_0']:'';
					$c2=$peo_ary[0]['a1_0']?$peo_ary[0]['a1_0']:'';
					$c3=$c1+$c2;
					$add_ary=array('classid'=>$ary,'month'=>'pe_sum','total_pe'=>$c3,'sum_ren'=>$c1,'no_ren'=>$c2);	
			
				}else{
					$c3=0;
					$add_ary="";
				}
					
					$ary_month=$this->db->findSql($sql);
					
					if($ary_month){
						$a1=$a2=$a3=$s_pe=0;
						foreach($ary_month as $item){
							
							if($item["cd0"]){
								$a1+=1;//次数
								$a2+=$item["cd0"];
							}
						
					}
						
						if(!$a1){
							$a1="";
						}
						
						if(!$a2){
							$a2="";
						}
	
		
						$ary_list[]=array('classid'=>$ary,'month'=>$i,'sum_ren'=>$a1,'no_ren'=>$a2?$a2:'');	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
			
			}//endforeach
			
			//取得班级名称
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"]?$item["sum_ren"]:"";//本数
					$n_total+=$item["no_ren"]?$item["no_ren"]:"";//字数
					$month=$item["month"];
					$sum+=$item["total_pe"];
				}
			}
			
			$xi=0;
			
			$ary_list[]=array('classid'=>$ary,'month'=>'total','xiaolu'=>$xi,'total_pe'=>$sum?$sum:'',"sum_ren"=>$s_total?$s_total:'',"no_ren"=>$n_total?$n_total:'');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			$ary_row[]=array($class_name,$ary_list,$c3);
		
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
		foreach($ary_row as $pitem){
			$inner+=$pitem[2];
		}
		$this->add_t=$inner;//总人数
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100);
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
		$stt=$this->addmonth("total",$ary_rows,1);
		$ary_total[]=$stt;//小计底部总计	
				
		$one_ary=$ary_total[0];
		$girl=$one_ary["n_total"];
		$boy=$one_ary["s_total"];
		$all=$one_ary["total_pe"];
		
		
		$this->str_name="总计";
		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
			
		$this->display('tables/C06B.html');
		
		//14、	C06B代理家长统计表
	}
	
	
	
	
	function C06C(){
	/*C06C 各学校代理家长汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
				$sql="select cd0 from class_statistics_each_day where classid in(select id  from classes where schoolid=$school_id) and cdate>='$start_time' and cdate<='$end_time '";


					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $item){
							
							if($item){
								if($item["cd0"]){
									$tian+=1;//天数
									$num+=$item["cd0"];
								}
								$total+=$tian;
								$sum+=$num;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			if(!$sum || !$total){
				$sum="";
				$total="";
			}
			$ary_list[]=array('cishu'=>$total,'tian'=>$sum,'classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/C06C.html');
	}
	
	
	
	function C07B(){
	/*C07B  结对帮扶统计表
	 * $schoolid
	 * termid
	 *
	 */
			
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		
		$ary=$this->month_ary($cfrom,$cto);//得到月份
		$s_year=date("Y",strtotime($cfrom));
		$e_year=date("Y",strtotime($cto));
		
		$ary_row=array();
		$total=0;
		$sum=0;
			
		foreach($ary as $key=>$item){//月份揗环
			if($item>12){
				$ary[$key]=$item-12;
				$year=$e_year;
				$item=$item-12;
				
			}else{
				$year=$s_year;
			}
			$s_time=$year."-".$item."-"."1";
			$day=$this->return_day($item);
			$s_end=$year."-".$item."-".$day;
			$ary_col[]=$this->return_month($item);
			
			$a1=$a2=0;
			$sql="select c0,c1  from school_statistics_each_month where cdate>='$s_time' and cdate<='$s_end' and schoolid=$schoolid ";
			$ary_terms=$this->db->findSql($sql);

			foreach($ary_terms as $row){
				if($row){
					if($row["c0"]!=""){
						$a1+=$row["c0"];
					}
					if($row["c1"]!=""){
						$a2+=$row["c1"];
					}
					$total+=$row["c0"];
					$sum+=$row["c1"];
				}
				
			}
			
			$ary_list[]=array("ci"=>$a2?$a2:'',"ren"=>$a1?$a1:'');
			
			
		}//endforeach
		
		
		$ary_col[count($ary_col)]="小计";
		$this->month_ary=$ary_col;
	
		array_push($ary_list,array("ren"=>$total?$total:'',"ci"=>$sum?$sum:''));
		$this->ary_list=$ary_list;
		
		$this->display('tables/C07B.html');
	}
	
	
	
	
	function C07C(){
	/*C06C 各学校代理家长汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			

					$sql="select c0,c1  from school_statistics_each_month where schoolid=$school_id and cdate>='$start_time' and cdate<='$end_time' ";

					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $row){
							
							if($row){
								if($row["c0"]!=""){
									$tian+=$row["c0"];
								}
								if($row["c1"]!=""){
									$num+=$row["c1"];
								}
								$total+=$num;
								$sum+=$tian;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
		
			$ary_list[]=array('cishu'=>$total?$total:'','tian'=>$sum?$sum:'','classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/C07C.html');
	}
	
	
	
	
	function C10B(){
		/*C09B 心里辅导统计表
		 * $schoolid
		 * termid
		 *
		 */
			
			$schoolid = $this->schoolid;    //取当前学校ID
			//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
			$termid = $this->spArgs('termid', 1);//默认第一学期
			$this->termid = $termid;  
			$sql_terms="select * from terms where id =$termid ";
			$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
			$cfrom=$ary_terms[0]['cfrom'];
			$cto=$ary_terms[0]['cto'];
			
			$ary=$this->month_ary($cfrom,$cto);//得到月份
			$s_year=date("Y",strtotime($cfrom));
			$e_year=date("Y",strtotime($cto));
			
			$ary_row=array();
			$total=0;
			$sum=0;
				
			foreach($ary as $key=>$item){
				if($item>12){
					$ary[$key]=$item-12;
					$year=$e_year;
					$item=$item-12;
					
				}else{
					$year=$s_year;
				}
				$s_time=$year."-".$item."-"."1";
				$day=$this->return_day($item);
				$s_end=$year."-".$item."-".$day;
				$ary_col[]=$this->return_month($item);
				
				$a1=$a2=0;
				$sql="select c2,c3  from school_statistics_each_month where cdate>='$s_time' and cdate<='$s_end' ";
				$ary_terms=$this->db->findSql($sql);
				foreach($ary_terms as $row){
					if($row){
						if($row["c2"]!=""){
							$a1+=$row["c2"];
						}
						if($row["c3"]!=""){
							$a2+=$row["c3"];
						}
						$total+=$row["c2"];
						$sum+=$row["c3"];
					}
				}
				$ary_list[]=array("ren"=>$a1?$a1:'',"ci"=>$a2?$a2:'');
				
			}//endforeach
			
			$ary_col[count($ary_col)]="小计";
			$this->month_ary=$ary_col;
		
			array_push($ary_list,array("ren"=>$total,"ci"=>$sum));
			$this->ary_list=$ary_list;
			
			$this->display('tables/C10B.html');
			
	}
	
	
	
	function C09D(){
	/*C09D 各学校心理辅导汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			

					$sql="select c2,c3  from school_statistics_each_month where schoolid=$school_id and cdate>='$start_time' and cdate<='$end_time' ";

					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $row){
							
							if($row){
								if($row["c2"]!=""){
									$tian+=$row["c2"];
								}
								if($row["c3"]!=""){
									$num+=$row["c3"];
								}
								$total+=$num;
								$sum+=$tian;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
		
			$ary_list[]=array('cishu'=>$total?$total:'','tian'=>$sum?$sum:'','classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	

		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/C09D.html');
	}
	
	
	
	
	
	
	function C12B(){
		/*C10B 知心姐姐信箱统计表 
		 * $schoolid
		 * termid
		 *
		 */
			
			$schoolid = $this->schoolid;    //取当前学校ID
			//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
			$termid = $this->spArgs('termid', 1);//默认第一学期
			$this->termid = $termid;  
			$sql_terms="select * from terms where id =$termid ";
			$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
			$cfrom=$ary_terms[0]['cfrom'];
			$cto=$ary_terms[0]['cto'];
			
			$ary=$this->month_ary($cfrom,$cto);//得到月份
			$s_year=date("Y",strtotime($cfrom));
			$e_year=date("Y",strtotime($cto));
			
			$ary_row=array();
			$total=0;
			$sum=0;
				
			foreach($ary as $key=>$item){
				if($item>12){
					$ary[$key]=$item-12;
					$year=$e_year;
					$item=$item-12;
					
				}else{
					$year=$s_year;
				}
				$s_time=$year."-".$item."-"."1";
				$day=$this->return_day($item);
				$s_end=$year."-".$item."-".$day;
				$ary_col[]=$this->return_month($item);
				
				$a1=$a2=0;
				$sql="select c4,c5 from school_statistics_each_month where cdate>='$s_time' and cdate<='$s_end' ";
				$ary_terms=$this->db->findSql($sql);
				foreach($ary_terms as $row){
					if($row){
						if($row["c4"]!=""){
							$a1+=$row["c4"];
						}
						if($row["c5"]!=""){
							$a2+=$row["c5"];
						}
						$total+=$a1;
						$sum+=$a2;
					}
				}
				$ary_list[]=array("ren"=>$a1?$a1:'',"ci"=>$a2?$a2:'');
				
			}//endforeach
			
			$ary_col[count($ary_col)]="小计";
			$this->month_ary=$ary_col;
		
			array_push($ary_list,array("ren"=>$total?$total:'',"ci"=>$sum?$sum:''));
			$this->ary_list=$ary_list;
			
			$this->display('tables/C12B.html');
			
	}
	
	
	function C10C(){
		
	/*C10C 各学校知心姐姐信箱汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
			
				$sql="select c4,c5 from school_statistics_each_month where schoolid=$school_id and cdate>='$start_time' and cdate<='$end_time' ";

					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $row){
							
							if($row){
								if($row["c4"]!=""){
									$tian+=$row["c4"];
								}
								if($row["c5"]!=""){
									$num+=$row["c5"];
								}
								$total+=$num;
								$sum+=$tian;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
		
			$ary_list[]=array('cishu'=>$total?$total:'','tian'=>$sum?$sum:'','classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	


		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/C10C.html');
	
	
	}
	
	
	function  D09B(){
		/*D09B 礼仪教育统计表
		 * $schoolid
		 * termid
		 *
		 */
		 
	 $schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		$str="";
		foreach($ary_classes as $row){
			$str.=$row["id"].",";
		}
		
		$str=substr($str,0,strlen($str)-1);
		
		if($str){
			$sql="select d8,d9,cdate,classid from class_statistics_each_day where cdate>='$cfrom' and cdate<='$cto' and classid in($str) ";
		}else{
			$sql="select d8,d9,cdate,classid from class_statistics_each_day where cdate>='$cfrom' and cdate<='$cto'  ";
		}
		
		$ary_terms=$this->db->findSql($sql);
		$have_terms=array();
		if($ary_terms){
			foreach($ary_terms as $key=>$item){
				if($ary_classes){
					foreach($ary_classes as $class){
						if($class["id"]==$item["classid"]){
							if($item["d8"]!=""){
								$have_terms[]=array("d8"=>$item["d8"],"d9"=>$item["d9"],'cdate'=>$item["cdate"],"classid"=>$class['classname']);
							}
						}
					}
				}//endif;
			}//endforeach;
		}
		
		$this->ary_list=$have_terms;
		
		$this->display('tables/D09B.html');
	}
	
	
	function D09D(){
	/*D09D 各学校礼仪教育汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		$ary_col=array();// 显示列的月数
		$ary_row=array();
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}

		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		for($k=$s_time;$k<=$col_end;$k++){
			if($k<=12){
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
			
		}
		
		array_push($ary_col,"小计");
		$this->this_col=$ary_col;
		
						
		$ary_list=array();
	
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				
				
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
			
			$temp=0;
			
			for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
			
			
				$sql="select d8,d9,cdate,classid from class_statistics_each_day where cdate>='$start_time' and cdate<='$end_time' and classid in(select id from classes where schoolid=$school_id) ";

					$ary_month=$this->db->findSql($sql);
					$tian=0;
					$num=0;
					
					
					if($ary_month){
						
						//$tian=0;
						foreach($ary_month as $row){
							
							if($row){
								if($row["d8"]!=""){
									$num+=1;
								}
								
								$total+=$num;
								$sum+=$tian;
							}
							
						}//endforeach
						
						$ary_list[]=array('cishu'=>$num?$num:'','tian'=>$tian?$tian:'','month'=>$i);	
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
			}//endforeach
			
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$total=0;
			$sum=0;
			$month=0;
			
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
		
			$ary_list[]=array('cishu'=>$total?$total:'','tian'=>$sum?$sum:'','classid'=>$ary,'month'=>'total');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$total+=$item["cishu"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
			$ary_rows=array();
			foreach($ary_row as $item){
				$ary_rows[]=$item[1];
			}
		
	//total row
	for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
		if($r>12){
			$s=$r-12;
		}else{
			$s=$r;
		}
			
		$ary_total[]=$this->addmonth($s,$ary_rows);
	}
	
	$ary_total[]=$this->addmonth("total",$ary_rows);
	


		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/D09D.html');
	
	}
	
	
	function D01B(){

	 /*D01C晨练出勤统计表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		//	$s_total+=$this->return_day($s);
		}//endfor
		
		$ary_col[]="小计";
		$this->this_col=$ary_col;//表头月份
		
		
		foreach($ary_classid as $ary){//循环班级得到每月统计记录
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
				//
				//
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
			$temp=0;
			
		for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
				
				$sql="select d0, d1,d2,classid  from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
			
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_day=0;
						foreach($ary_month as $item){
							
							if($item["d0"]){
								$a1+=$item["d0"];
							}
							if($item["d1"]){
								$a2+=$item["d1"];
							}
							if($item["d2"]){
								$a3+=$item["d2"];
							}
							if($item["d0"]!="" ||$item["d1"]!="" || $item["d2"]!=""){
								$s_day+=1;
							}
						}
	
						$tian=$s_day?$s_day:'';//当前月出勤天数
						$day=$this->return_day($i);//当前月分天数
						$xiao=round((($a1-$a3)/$a1)*100)?round((($a1-$a3)/$a1)*100).'%':'';//本月出勤率
						
		
						$ary_list[]=array('tian'=>$tian,'classid'=>$ary,'month'=>$i,'xiaolu'=>$xiao,'sum_ren'=>$a1,'no_ren'=>$a3);	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
						
			}//endforeach
			
			//取得班级名称
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"];
					$n_total+=$item["no_ren"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
			}
			
			if(!$sum ){
				$sum="";
			}
	
			$xi=round((($s_total-$n_total)/$s_total)*100)?round((($s_total-$n_total)/$s_total)*100).'%':'';
			
			$ary_list[]=array('tian'=>$sum,'classid'=>$ary,'month'=>'total','xiaolu'=>$xi,"sum_ren"=>$s_total,"no_ren"=>$n_total);//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($class_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100).'%';
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
	
		$stt=$this->addmonth("total",$ary_rows,1);
		$stt['ci']=round((($stt["s_total"]-$stt['n_total'])/$stt["s_total"])*100).'%';
		$ary_total[]=$stt;//小计底部总计
	
			
		$this->str_name="总计";

		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
	
		
		$this->display('tables/D01B.html');

  }
	
	
	
		
	function D01D(){

	 /*D01D 各学校晨练出勤汇总表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_schools="select * from schools ";
		$ary_schools=$this->db->findSql($sql_schools);//得到学校下的班级
		
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
		$this->this_col=$ary_col;//表头月份
		
		
		foreach($ary_schools as $ary){//循环班级得到每月统计记录
		$school_id=$ary["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));
			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
			$temp=0;
			
		for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
				
				$sql="select d0, d1,d2,classid  from class_statistics_each_day where classid in(select id from classes where schoolid=$school_id ) and cdate>='$start_time' and cdate<='$end_time '";
			
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_day=0;
						foreach($ary_month as $item){
							
							if($item["d0"]){
								$a1+=$item["d0"];
							}
							if($item["d1"]){
								$a2+=$item["d1"];
							}
							if($item["d2"]){
								$a3+=$item["d2"];
							}
							if($item["d0"]!="" ||$item["d1"]!="" || $item["d2"]!=""){
								$s_day+=1;
							}
						}
	
						$tian=$s_day?$s_day:'';//当前月出勤天数
						$day=$this->return_day($i);//当前月分天数
						$xiao=round((($a1-$a3)/$a1)*100)?round((($a1-$a3)/$a1)*100).'%':'';//本月出勤率
						
		
						$ary_list[]=array('tian'=>$tian,'classid'=>$ary,'month'=>$i,'xiaolu'=>$xiao,'sum_ren'=>$a1,'no_ren'=>$a3);	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
						
			}//endforeach
			
			//取得班级名称
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
	
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"];
					$n_total+=$item["no_ren"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
			}
			
			if(!$sum ){
				$sum="";
			}
	
			$xi=round((($s_total-$n_total)/$s_total)*100)?round((($s_total-$n_total)/$s_total)*100).'%':'';
			
			$ary_list[]=array('tian'=>$sum,'classid'=>$ary,'month'=>'total','xiaolu'=>$xi,"sum_ren"=>$s_total,"no_ren"=>$n_total);//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100).'%';
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
	
		$stt=$this->addmonth("total",$ary_rows,1);
		$stt['ci']=round((($stt["s_total"]-$stt['n_total'])/$stt["s_total"])*100).'%';
		$ary_total[]=$stt;//小计底部总计
	
			
		$this->str_name="总计";

		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
	
		
		$this->display('tables/D01D.html');

  }
	
	
	
	function D02B(){

	 /*	D02C大课间出勤统计表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
		$this->this_col=$ary_col;//表头月份
		
		foreach($ary_classid as $ary){//循环班级得到每月统计记录
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));

			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
			$temp=0;
			
		for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
				
				$sql="select d3, d4,d5,classid  from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
			
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_day=0;
						foreach($ary_month as $item){
							
							if($item["d3"]){
								$a1+=$item["d3"];
							}
							if($item["d4"]){
								$a2+=$item["d4"];
							}
							if($item["d5"]){
								$a3+=$item["d5"];
							}
							if($item["d3"]!="" ||$item["d4"]!="" || $item["d5"]!=""){
								$s_day+=1;
							}
						}
	
						$tian=$s_day?$s_day:'';//当前月出勤天数
						$day=$this->return_day($i);//当前月分天数
						$xiao=round((($a1-$a3)/$a1)*100)?round((($a1-$a3)/$a1)*100).'%':'0%';//本月出勤率
						
		
						$ary_list[]=array('tian'=>$tian,'classid'=>$ary,'month'=>$i,'xiaolu'=>$xiao,'sum_ren'=>$a1,'no_ren'=>$a3);	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
						
			}//endforeach
			
			//取得班级名称
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"];
					$n_total+=$item["no_ren"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
			}
			
			if(!$sum ){
				$sum="";
			}
	
			$xi=round((($s_total-$n_total)/$s_total)*100)?round((($s_total-$n_total)/$s_total)*100).'%':'';
			
			$ary_list[]=array('tian'=>$sum,'classid'=>$ary,'month'=>'total','xiaolu'=>$xi,"sum_ren"=>$s_total,"no_ren"=>$n_total);//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($class_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100).'%';
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
	
		$stt=$this->addmonth("total",$ary_rows,1);
		$stt['ci']=round((($stt["s_total"]-$stt['n_total'])/$stt["s_total"])*100).'%';
		$ary_total[]=$stt;//小计底部总计
	
			
		$this->str_name="总计";

		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
	
		
		$this->display('tables/D02B.html');

  }
    
		
		
		
	function D02D(){

	 /*	D02D大课间出勤汇总表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_schools="select * from schools  ";
		$ary_schools=$this->db->findSql($sql_schools);//得到学校下的班级
		
	
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
		$this->this_col=$ary_col;//表头月份
		
		foreach($ary_schools as $ary){//循环学校得到每月统计记录
		$school_id=$ary["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));

			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		
			$temp=0;
			
		for($i=$start;$i<=$end;$i++){//循环月份
		
				$temp=$i;
				
				if($i>12){
						$i=$i-12;
						
						$start_time=$e_year."-".$i."-"."1";
						if($e_time==$i){
							
							$end_time=$cto;
							
						}else{
							$day=$this->return_day($i);
							$end_time=$e_year."-".$i."-".$day;
						}
					}else{
					
						 $day=$this->return_day($i);
							$end_time=$year."-".$i."-".$day;
							if($i==$s_time){
								$start_time=$cfrom;
							}else{
								$start_time=$year."-".$i."-"."1";
							}
						
					}
				
				$sql="select d3, d4,d5,classid  from class_statistics_each_day where classid in(select id from classes where schoolid=$school_id) and cdate>='$start_time' and cdate<='$end_time '";
			
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_day=0;
						foreach($ary_month as $item){
							
							if($item["d3"]){
								$a1+=$item["d3"];
							}
							if($item["d4"]){
								$a2+=$item["d4"];
							}
							if($item["d5"]){
								$a3+=$item["d5"];
							}
							if($item["d3"]!="" ||$item["d4"]!="" || $item["d5"]!=""){
								$s_day+=1;
							}
						}
	
						$tian=$s_day?$s_day:'';//当前月出勤天数
						$day=$this->return_day($i);//当前月分天数
						$xiao=round((($a1-$a3)/$a1)*100)?round((($a1-$a3)/$a1)*100).'%':'';//本月出勤率
						
		
						$ary_list[]=array('tian'=>$tian,'classid'=>$ary,'month'=>$i,'xiaolu'=>$xiao,'sum_ren'=>$a1,'no_ren'=>$a3);	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
				
						
			}//endforeach
			
			//取得班级名称
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"];
					$n_total+=$item["no_ren"];
					$sum+=$item["tian"];
					$month=$item["month"];
				}
			}
			
			if(!$sum ){
				$sum="";
			}
	
			$xi=round((($s_total-$n_total)/$s_total)*100)?round((($s_total-$n_total)/$s_total)*100).'%':'';
			
			$ary_list[]=array('tian'=>$sum,'classid'=>$ary,'month'=>'total','xiaolu'=>$xi,"sum_ren"=>$s_total,"no_ren"=>$n_total);//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100).'%';
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
	
		$stt=$this->addmonth("total",$ary_rows,1);
		$stt['ci']=round((($stt["s_total"]-$stt['n_total'])/$stt["s_total"])*100).'%';
		$ary_total[]=$stt;//小计底部总计
	
			
		$this->str_name="总计";

		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
	
		
		$this->display('tables/D02D.html');

  }
    
	
	
	
	function D04B(){
	 /*	D04B学生洗浴统计表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
		
		array_unshift($ary_col,"班级人数");		
		
		$this->this_col=$ary_col;//表头月份
		
		foreach($ary_classid as $ary){//循环班级得到每月统计记录
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));

			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		$temp=$pk=0;
			
		for($i=$start;$i<=$end;$i++){//循环月份
			$pk++;
			$temp=$i;
			if($i>12){
					$i=$i-12;
					
					$start_time=$e_year."-".$i."-"."1";
					if($e_time==$i){
						
						$end_time=$cto;
						
					}else{
						$day=$this->return_day($i);
						$end_time=$e_year."-".$i."-".$day;
					}
				}else{
				
					 $day=$this->return_day($i);
						$end_time=$year."-".$i."-".$day;
						if($i==$s_time){
							$start_time=$cfrom;
						}else{
							$start_time=$year."-".$i."-"."1";
						}
				}
				
				$add_ary;
				
				$sql="select d6, d7,classid  from class_statistics_each_day where classid= ".$ary ." and cdate>='$start_time' and cdate<='$end_time '";
				
				$str_sql="select a0_0,a1_0 from class_statistics_each_term where classid=$ary and termid=$termid";//每班人数

				$peo_ary=$this->db->findSql($str_sql);
			
				$c1=$c2=$c3=0;
				if($peo_ary){
					$c1=$peo_ary[0]['a0_0']?$peo_ary[0]['a0_0']:'';
					$c2=$peo_ary[0]['a1_0']?$peo_ary[0]['a1_0']:'';
					$c3=$c1+$c2;
					$add_ary=array('classid'=>$ary,'month'=>'pe_sum','total_pe'=>$c3,'sum_ren'=>$c1,'no_ren'=>$c2);	
			
				}else{
					$add_ary=array();
				}
				
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_pe=0;
						foreach($ary_month as $item){
							
							if($item["d6"]){
								$a1+=$item["d6"];//男
							}
							if($item["d7"]){
								$a2+=$item["d7"];//女
							}
						
							$s_pe+=($a1+$a2);//小计
						}
						
						if(!$a1){
							$a1="";
						}
						
						if(!$a2){
							$a2="";
						}
	
						$total_pe=$s_pe?$s_pe:'';//当前月洗浴次数
						
						$ary_list[]=array('classid'=>$ary,'month'=>$i,'total_pe'=>$total_pe,'sum_ren'=>$a1,'no_ren'=>$a2);	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
			
			}//endforeach
			
			
				array_unshift($ary_list,$add_ary);
						
			
			//取得班级名称
			$class_name="";
			foreach($ary_classes as $item){
				if($ary==$item["id"]){
					$class_name=$item["classname"];
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
			foreach($ary_list as $item){
				if($item){
					$s_total+=$item["sum_ren"]?$item["sum_ren"]:"";//男
					$n_total+=$item["no_ren"]?$item["no_ren"]:"";//女
					$month=$item["month"];
					$sum+=$item["total_pe"];
				}
			}
			
			
			$xi=0;
			
			$ary_list[]=array('classid'=>$ary,'month'=>'total','xiaolu'=>$xi,'total_pe'=>$sum?$sum:'',"sum_ren"=>$s_total?$s_total:'',"no_ren"=>$n_total?$n_total:'');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($class_name,$ary_list,1);
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
			$add_str=$this->addmonth("pe_sum",$ary_rows,1);//添加一列值
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100).'%';
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
		$stt=$this->addmonth("total",$ary_rows,1);
		$ary_total[]=$stt;//小计底部总计
		array_unshift($ary_total,$add_str);
		
		//$tt=count($ary_total);
		
		$one_ary=$ary_total[0];
		$girl=$one_ary["n_total"];
		$boy=$one_ary["s_total"];
		$all=$one_ary["total_pe"];
		
		$center_ary=array_slice($ary_total,1,count($ary_total)-1);
		$last_ary=array();
		foreach($center_ary as $key=>$avg){
			$a_num=1;
			if($key==(count($center_ary)-1)){
				$a_num=$pk;
			}

			$s_boy=round(($avg["s_total"]/($boy*$a_num))*100)?round(($avg["s_total"]/($boy*$a_num))*100).'%':'';
			$n_girl=round(($avg["n_total"]/($girl*$a_num))*100)?round(($avg["n_total"]/($girl*$a_num))*100).'%':'';
			$s_all=round(($avg["total_pe"]/($all*$a_num))*100)?round(($avg["total_pe"]/($all*$a_num))*100).'%':'';
			$last_ary[]=array("ci"=>'',"ti"=>'',"s_total"=>$s_boy,"n_total"=>$n_girl,"total_pe"=>$s_all);
		}
	
		array_unshift($last_ary,array());//最后一条记录——平均值

		$this->str_name="总计";
		$this->str_name2="人均";
		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
		$this->avg_row=$last_ary;
			
		$this->display('tables/D04B.html');
	}
	
	
	
	function D04C(){
	 /*	D04C 各学校学生洗浴汇总表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		$sql_schools="select * from schools ";
		$ary_schools=$this->db->findSql($sql_schools);//得到学校下的班级
		
	
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
	
		$s_time=date( "m",strtotime($cfrom));
		$s_year=date("Y",strtotime($cfrom));
		$e_time=date( "m",strtotime($cto));
		$e_year=date('Y',strtotime($cto));
		
		$ary_col=array();// 月份列表
		$ary_row=array();
		$ary_list=array();//记录列表
		$s_total=0;//统计天数
		
		if($s_year!=$e_year){
			$col_end=12+$e_time;
		}else{
			$col_end=$e_time;
		}
	
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
	
		for($k=$s_time;$k<=$col_end;$k++){
			$s=$k;
			if($k<=12){
				
				$ary_col[]=$this->return_month($k);
			}else{
				
				$s=$k-12;
				$ary_col[]=$this->return_month($s);
			}
		}//endfor
		
		$ary_col[]="小计";
		
		array_unshift($ary_col,"班级人数");		
		
		$this->this_col=$ary_col;//表头月份
		
		foreach($ary_schools as $ary){//循环年级得到每月统计记录
			$school_id=$ary["id"];
			$start=0;
			$end=0;
			$ary_month=array();
			
			if($s_year!=$e_year){
				$start=$s_time;
				$end=12+$e_time;
				$year=date("Y",strtotime($cfrom));

			}else{
				
				$start=$s_time;
				$end=$e_time;
				$year=date("Y",strtotime($cfrom));
			}
		
		$temp=$pk=0;
			
		for($i=$start;$i<=$end;$i++){//循环月份
			$pk++;
			$temp=$i;
			if($i>12){
					$i=$i-12;
					
					$start_time=$e_year."-".$i."-"."1";
					if($e_time==$i){
						
						$end_time=$cto;
						
					}else{
						$day=$this->return_day($i);
						$end_time=$e_year."-".$i."-".$day;
					}
				}else{
				
					 $day=$this->return_day($i);
						$end_time=$year."-".$i."-".$day;
						if($i==$s_time){
							$start_time=$cfrom;
						}else{
							$start_time=$year."-".$i."-"."1";
						}
				}
				
				$add_ary;
				
				$sql="select d6, d7,classid  from class_statistics_each_day where classid in(select id from classes where schoolid=$school_id ) and cdate>='$start_time' and cdate<='$end_time '";
				
				$str_sql="select a0_0,a1_0 from class_statistics_each_term where classid in(select id from classes where schoolid=$school_id)";//每班人数

				$peo_ary=$this->db->findSql($str_sql);
			
				$c1=$c2=$c3=0;
				if($peo_ary){
					foreach($peo_ary as $pitem){
					$c1+=$pitem['a0_0']?$pitem['a0_0']:'';
					$c2+=$pitem['a1_0']?$pitem['a1_0']:'';
					$c3+=$pitem['a0_0']+$pitem['a1_0'];
					}
					$add_ary=array('classid'=>$ary,'month'=>'pe_sum','total_pe'=>$c3,'sum_ren'=>$c1,'no_ren'=>$c2);	
			
				}else{
					$add_ary=array();
				}
				
					$ary_month=$this->db->findSql($sql);
					
					//每月出勤天数/率
					if($ary_month){
						$a1=$a2=$a3=$s_pe=0;
						foreach($ary_month as $item){
							
							if($item["d6"]){
								$a1+=$item["d6"];//男
							}
							if($item["d7"]){
								$a2+=$item["d7"];//女
							}
						
							$s_pe+=$item["d6"]+$item["d7"];//小计
						}
						
						if(!$a1){
							$a1="";
						}
						
						if(!$a2){
							$a2="";
						}
	
						$total_pe=$s_pe?$s_pe:'';//当前月洗浴次数
						$ary_list[]=array('classid'=>$ary,'month'=>$i,'total_pe'=>$total_pe,'sum_ren'=>$a1,'no_ren'=>$a2);	
						
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
				$i=$temp;		
			
			}//endforeach
			
			
				array_unshift($ary_list,$add_ary);
						
			
			//取得班级名称
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$sum=0;
			$month=0;
			$s_total=0;
			$n_total=0;
			
			
		//dump($ary_list);
			
			foreach($ary_list as $key=>$item){
			
				if($item){
					if($key==0){
						$s_total+=0;//男
						$n_total+0;//女
						$month=$item["month"];
						$sum+=0;
					}else{
						$s_total+=$item["sum_ren"]?$item["sum_ren"]:"";//男
						$n_total+=$item["no_ren"]?$item["no_ren"]:"";//女
						$month=$item["month"];
						$sum+=$item["total_pe"];
					}
				}
			}
			
			$xi=0;
			
			$ary_list[]=array('classid'=>$ary,'month'=>'total','xiaolu'=>$xi,'total_pe'=>$sum?$sum:'',"sum_ren"=>$s_total?$s_total:'',"no_ren"=>$n_total?$n_total:'');//添加小计
			
			$ary_total=array();
			
			foreach($ary_list as $item){
				
				if($item){
					$sum+=$item["tian"];
					$month=$item["month"];
				}
				
			}
			
			$ary_row[]=array($school_name,$ary_list,1);
			$total_row=array();
		
			$ary_list="";
		}
		
		$ary_rows=array();//班级记录
			
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}
			
			$add_str=$this->addmonth("pe_sum",$ary_rows,1);//添加一列值
			
		//每月底部总计
		for($r=$col_total['c_start'];$r<=$col_total["c_end"];$r++){
			if($r>12){
				$s=$r-12;
			}else{
				$s=$r;
			}
			
			$str=$this->addmonth($s,$ary_rows,1);

			if($str["ti"]){
				
				$xi=round((($str["s_total"]-$str['n_total'])/$str["s_total"])*100).'%';
				$str['ci']=$xi;
				
			}
			$ary_total[]=$str;
		}
		
		$stt=$this->addmonth("total",$ary_rows,1);
		$ary_total[]=$stt;//小计底部总计
		array_unshift($ary_total,$add_str);
		
		$this->str_name="总计";
		$this->tab_col=$ary_col;//表关月份
		$this->lists=$ary_row;//显示数据
		$this->total_row=$ary_total;//底部总计
			
		$this->display('tables/D04C.html');
	}
	
	
    
	
	function M22B(){
	 /*接受资助统计表
		 * $schoolid
		 * termid
		 *
		 */
			
			$schoolid = $this->schoolid;    //取当前学校ID
			//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
			$termid = $this->spArgs('termid', 1);//默认第一学期
			$this->termid = $termid;  
			$sql_terms="select * from terms where id =$termid ";
			$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
			$cfrom=$ary_terms[0]['cfrom'];
			$cto=$ary_terms[0]['cto'];
			
			$sql="select  *  from school_statistics_each_week_2 where schoolid=$schoolid and cdate>='$cfrom' and cdate<='$cto'";
			$ary_list=$this->db->findSql($sql);
			
			$this->ary_list=$ary_list;
	
	
		$this->display('tables/M22B.html');
	}
	
	
	function M22C(){
		
		/*接受资助汇总统计表
		 * $schoolid
		 * termid
		 *
		 */
			
			$schoolid = $this->schoolid;    //取当前学校ID
			//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
			$termid = $this->spArgs('termid', 1);//默认第一学期
			$this->termid = $termid;  
			$sql_terms="select * from terms where id =$termid ";
			$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
			$cfrom=$ary_terms[0]['cfrom'];
			$cto=$ary_terms[0]['cto'];
			
			$sql="select  a.m3,a.m4,a.m5,a.cdate,b.schoolname,b.zone from school_statistics_each_week_2 as a,schools as b where  a.schoolid=b.id and  a.cdate>='$cfrom' and a.cdate<='$cto' order by a.schoolid desc";
		
			$ary_list=$this->db->findSql($sql);
			
			$this->ary_list=$ary_list;

		
		$this->display('tables/M22C.html');
	}
	
	
	function E02B(){
	/*营养菜单统计表
	 * $schoolid
	 * termid
	 *
	 */
	 $schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		$sum=0;
		
		$ary=$this->month_ary($cfrom,$cto);
		$s_year=date("Y",strtotime($cfrom));
		$e_year=date("Y",strtotime($cto));
		
		$ary_row=array();
			
		foreach($ary as $key=>$item){
			if($item>12){
				$ary[$key]=$item-12;
				$year=$e_year;
				$item=$item-12;
				
			}else{
				$year=$s_year;
			}
			$s_time=$year."-".$item."-"."1";
			$day=$this->return_day($item);
			$s_end=$year."-".$item."-".$day;
			$ary_col[]=$this->return_month($item);
			
			$a1=$a2=$a2=$a3=$a4=0;
			$sql="select e0,e1,e2,e3  from school_statistics_each_month where cdate>='$s_time' and cdate<='$s_end' ";
			$ary_terms=$this->db->findSql($sql);
			$total=0;
			foreach($ary_terms as $row){
				if($row){
					if($row["e0"]!=""){
						$a1+=$row["e0"];
					}
					if($row["e1"]!=""){
						$a2+=$row["e1"];
					}
					if($row["e2"]!=""){
						$a3+=$row["e2"];
					}
					if($row["e3"]!=""){
						$a4+=$row["e3"];
					}
					$total=$a1+$a2+$a3;
				}//endif
			}
		$ary_rows[]=array($a1,$a2,$a3,$total,$a4);
		}

		for($i=0;$i<count($ary_rows[0]);$i++){
				$ary=array();
				$sum=0;
				for($j=0;$j<count($ary_rows);$j++){
				 array_unshift($ary,$ary_rows[($j)][$i]);
				 $sum+=$ary_rows[$j][$i];
				}
				
				 if($i==0){
					$str="白煮蛋";
				 }else if($i==1){
					 $str="卤蛋";
				 }else if($i==2){
					 $str="其它";
				 }else if($i==3){
					 $str="蛋小计";
				 }else{
					 $str="肉";
				 }
				array_unshift($ary,$str);
				array_push($ary,$sum);
				$ary_list[]=$ary;
			}
		$ary_col[count($ary_col)]="小计";
			$this->month_ary=$ary_col;
			$this->ary_list=$ary_list;
		
	
		$this->display('tables/E02B.html');
	}
	
	
	
	function E02C(){
	/*E02c 各学校营养菜单汇总表
	 * $schoolid
	 * termid
	 *
	 */
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		/********下面开始处理数据库的数据***************/
		
		$sql_school="select * from schools";
		$ary_schools=$this->db->findSql($sql_school);
		
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		$s_year=date("Y",strtotime($cfrom));
		$s_month=date("m",strtotime($cfrom));;
		$cfrom=$s_year."-".$s_month."-"."01";
		$col_total=array('c_start'=>$s_time,'c_end'=>$col_end);
		$ary_col=array("地区","学校","白煮蛋","卤蛋","其它","小计","肉(次数)");
		
		$this->this_col=$ary_col;
		$ary_list=array();
	
		$t1=$t2=$t3=$t4=$t5=0;
		foreach($ary_schools as $sch){//循环学校
			$school_id=$sch["id"];
			$sql="select e0,e1,e2,e3  from school_statistics_each_month where schoolid=$school_id and cdate>='$cfrom' and cdate<='$cto' ";

			$ary_month=$this->db->findSql($sql);
			$a1=$a2=$a3=$a4=$total=0;
					
					if($ary_month){
						foreach($ary_month as $row){
							
							if($row){
								if($row["e0"]!=""){
									$a1+=$row["e0"];
								}
								if($row["e1"]!=""){
									$a2+=$row["e1"];
								}
								if($row["e2"]!=""){
									$a3+=$row["e2"];
								}
								if($row["e3"]!=""){
									$a4+=$row["e3"];
								}
								
								$total+=$row["e0"]+$row["e1"]+$row["e2"];
								
							}
							
						}//endforeach
						
					$ary_list[]=array($a1?$a1:'',$a2?$a2:'',$a3?$a3:'',$total?$total:'',$a4?$a4:'');	
						$t1+=$a1;
						$t2+=$a2;
						$t3+=$a3;
						$t4+=$a4;
						$t5+=$total;
					}else{
						
						$ary_list[]="";
						
					}//endif ary_month
					
			
			$school_name="";
			foreach($ary_schools as $item){
				if($school_id==$item["id"]){
					$school_name=array($item["schoolname"],$item["zone"]?$item["zone"]:'-');
				}
			}
			
			$ary_row[]=array($school_name,$ary_list);
			$total_row=array();
		
			$ary_list="";
		}
		
		
		$ary_rows=array();
		foreach($ary_row as $item){
			$ary_rows[]=$item[1];
		}

		$ary_total=array($t1?$t1:'',$t2?$t2:'',$t3?$t3:'',$t5?$t5:'',$t4?$t4:'');
		$this->tab_col=$ary_col;
		$this->lists=$ary_row;
		$this->total_row=$ary_total;
		$this->display('tables/E02C.html');
	}
	
	function M21B(){
		
	/*	学校重大活动月统计表
	  * $schoolid
	  * termid
	  *
	  */
		
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$time=$this->spArgs('cdate');//
		$data["cdate"]=$time;
		$this->data=$data;
		
		$year=date("Y",strtotime($time));
		$month=date("m",strtotime($time));
			
		
		$days=$this->return_day($month);
		$ary_list=array();
		for($i=1;$i<=$days;$i++){
			$ymd = $year."-".$month."-".$i;
			$week=$this->getWeekName($ymd);
			$sql="select * from school_statistics_each_week where cdate ='$ymd' ";
			$row=$this->db->findSql($sql);
			$note="";
			if($row){
				
				$note=$row[0]["m0"]."<br>".$row[0]["m1"]."<br>".$row[0]["m2"];
			}
			$ary_list[]=array("day"=>$i,"week"=>$week,"note"=>$note?$note:'&nbsp;');
		}
		
		$count=35-count($ary_list);
		if($count){
			for($j=0;$j<$count;$j++){
				$ary_list[]=array("day"=>"&nbsp;","week"=>"&nbsp;","note"=>"&nbsp;");
			}
		}
		$this->ary_list=$ary_list;
		
		$this->display('tables/M21B.html');
	}
	
	function C03B(){
		/**
		C03B 亲情电话\视频\书信统计表 
		*/
		
	  $schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		$term = $this->tTerms->find(array('id'=>$termid));
        $sql = "SELECT SUM(ca0_0) AS sca0_0, SUM(ca0_1) AS sca0_1, SUM(ca0_2) AS sca0_2, SUM(ca0_3) AS sca0_3,
                 SUM(ca1_0) AS sca1_0, SUM(ca1_1) AS sca1_1, SUM(ca1_2) AS sca1_2, SUM(ca1_3) AS sca1_3,
                  SUM(ca2_0) AS sca2_0, SUM(ca2_1) AS sca2_1, SUM(ca2_2) AS sca2_2, SUM(ca2_3) AS sca2_3,
                   SUM(ca3_0) AS sca3_0, SUM(ca3_1) AS sca3_1, SUM(ca3_2) AS sca3_2, SUM(ca3_3) AS sca3_3,
                SUM(cb0_0) AS scb0_0, SUM(cb0_1) AS scb0_1, SUM(cb0_2) AS scb0_2, SUM(cb0_3) AS scb0_3,
                 SUM(cb1_0) AS scb1_0, SUM(cb1_1) AS scb1_1, SUM(cb1_2) AS scb1_2, SUM(cb1_3) AS scb1_3,
                  SUM(cb2_0) AS scb2_0, SUM(cb2_1) AS scb2_1, SUM(cb2_2) AS scb2_2, SUM(cb2_3) AS scb2_3,
                   SUM(cb3_0) AS scb3_0, SUM(cb3_1) AS scb3_1, SUM(cb3_2) AS scb3_2, SUM(cb3_3) AS scb3_3,
                SUM(cc0_0) AS scc0_0, SUM(cc0_1) AS scc0_1, SUM(cc0_2) AS scc0_2, SUM(cc0_3) AS scc0_3,
                 SUM(cc1_0) AS scc1_0, SUM(cc1_1) AS scc1_1, SUM(cc1_2) AS scc1_2, SUM(cc1_3) AS scc1_3,
                  SUM(cc2_0) AS scc2_0, SUM(cc2_1) AS scc2_1, SUM(cc2_2) AS scc2_2, SUM(cc2_3) AS scc2_3,
                   SUM(cc3_0) AS scc3_0, SUM(cc3_1) AS scc3_1, SUM(cc3_2) AS scc3_2, SUM(cc3_3) AS scc3_3,
                MONTH(cdate) AS month, classid, classname
                FROM class_statistics_each_day LEFT JOIN classes ON classid=classes.id
                WHERE classid IN (SELECT id FROM classes WHERE schoolid=$schoolid)
                AND cdate BETWEEN '".$term['cfrom']."' AND '".$term['cto']."'
                GROUP BY MONTH(cdate), classid ORDER BY classid DESC";
        
        $data = $this->tClassStatisticsEachDay->findSql($sql);
        
        $datas = array();
        foreach($data as $i)
        {
            $datas[$i['month'].'_'.$i['classid']] = $i;        
        }
        $this->datas = $datas;
        
        $mfrom = date('n', strtotime($term['cfrom']));
        $mto = date('n', strtotime($term['cto']));
        
        $months = array();
        $monthnums = array('一月', '二月', '三月', '四月', '五月', 
        '六月', '七月', '八月', '九月', '十月', 
        '十一月', '十二月');
        $i = $mfrom;
        while($i != $mto)
        {
            array_push($months, array('num'=>$i, 'text'=>$monthnums[$i-1]));
            if(++$i==13) $i=1;
        }
        array_push($months, array('num'=>$i, 'text'=>$monthnums[$i-1]));
        
        $this->months = $months;
        $this->classes = $this->tClasses->findAll(array('schoolid'=>$schoolid));
        
        
        //****************************************
        //下面开始统计人数，小计，以及总计
        //****************************************
        
        //人数
        $sql = "SELECT (0+a0_0)+(0+a1_0) AS total,
                        (0+a0_1)+(0+a0_2)+(0+a0_3)+(0+a1_1)+(0+a1_2)+(0+a1_3) AS total_liushou,
                        (0+a2_0)+(0+a3_0) AS total_zhusu,
                        classid,
                        classname
                FROM class_statistics_each_term LEFT JOIN classes ON classid=classes.id
                WHERE termid=$termid
                AND classid IN (SELECT id FROM classes WHERE schoolid=$schoolid)
                ORDER BY classid DESC";
        $total = $this->tClassStatisticsEachTerm->findSql($sql);
        $totals = array();
        foreach($total as $i)
        {
            $totals['c_'.$i['classid']] = $i;        
        }
        $this->totals = $totals;
        
        //小计
        $rtotal = array();
        foreach($data as $i)
        {
            $rtotal["c_".$i['classid']]['fumu_0'] += $i['sca0_0']+$i['scb0_0']+$i['scc0_0'];
            $rtotal["c_".$i['classid']]['xiongdi_0'] += $i['sca0_1']+$i['scb0_1']+$i['scc0_1'];
            $rtotal["c_".$i['classid']]['zufu_0'] += $i['sca0_2']+$i['scb0_2']+$i['scc0_2'];
            $rtotal["c_".$i['classid']]['other_0'] += $i['sca0_3']+$i['scb0_2']+$i['scc0_3'];
            
            $rtotal["c_".$i['classid']]['fumu_1'] += $i['sca1_0']+$i['scb1_0']+$i['scc1_0'];
            $rtotal["c_".$i['classid']]['xiongdi_1'] += $i['sca1_1']+$i['scb1_1']+$i['scc1_1'];
            $rtotal["c_".$i['classid']]['zufu_1'] += $i['sca1_2']+$i['scb1_2']+$i['scc1_2'];
            $rtotal["c_".$i['classid']]['other_1'] += $i['sca1_3']+$i['scb1_2']+$i['scc1_3'];
            
            $rtotal["c_".$i['classid']]['fumu_2'] += $i['sca2_0']+$i['scb2_0']+$i['scc2_0'];
            $rtotal["c_".$i['classid']]['xiongdi_2'] += $i['sca2_1']+$i['scb2_1']+$i['scc2_1'];
            $rtotal["c_".$i['classid']]['zufu_2'] += $i['sca2_2']+$i['scb2_2']+$i['scc2_2'];
            $rtotal["c_".$i['classid']]['other_2'] += $i['sca2_3']+$i['scb2_2']+$i['scc2_3'];
            
            $rtotal["c_".$i['classid']]['fumu_3'] += $i['sca3_0']+$i['scb3_0']+$i['scc3_0'];
            $rtotal["c_".$i['classid']]['xiongdi_3'] += $i['sca3_1']+$i['scb3_1']+$i['scc3_1'];
            $rtotal["c_".$i['classid']]['zufu_3'] += $i['sca3_2']+$i['scb3_2']+$i['scc3_2'];
            $rtotal["c_".$i['classid']]['other_3'] += $i['sca3_3']+$i['scb3_2']+$i['scc3_3'];
            
        }
        $this->rtotal = $rtotal;
        
        //总计
        $alldatas = array();
        foreach($data as $i)
        {
            $alldatas["m_".$i['month']]['fumu_0'] += $i['sca0_0']+$i['scb0_0']+$i['scc0_0'];
            $alldatas["m_".$i['month']]['xiongdi_0'] += $i['sca0_1']+$i['scb0_1']+$i['scc0_1'];
            $alldatas["m_".$i['month']]['zufu_0'] += $i['sca0_2']+$i['scb0_2']+$i['scc0_2'];
            $alldatas["m_".$i['month']]['other_0'] += $i['sca0_3']+$i['scb0_2']+$i['scc0_3'];
            
            $alldatas["m_".$i['month']]['fumu_1'] += $i['sca1_0']+$i['scb1_0']+$i['scc1_0'];
            $alldatas["m_".$i['month']]['xiongdi_1'] += $i['sca1_1']+$i['scb1_1']+$i['scc1_1'];
            $alldatas["m_".$i['month']]['zufu_1'] += $i['sca1_2']+$i['scb1_2']+$i['scc1_2'];
            $alldatas["m_".$i['month']]['other_1'] += $i['sca1_3']+$i['scb1_2']+$i['scc1_3'];
            
            $alldatas["m_".$i['month']]['fumu_2'] += $i['sca2_0']+$i['scb2_0']+$i['scc2_0'];
            $alldatas["m_".$i['month']]['xiongdi_2'] += $i['sca2_1']+$i['scb2_1']+$i['scc2_1'];
            $alldatas["m_".$i['month']]['zufu_2'] += $i['sca2_2']+$i['scb2_2']+$i['scc2_2'];
            $alldatas["m_".$i['month']]['other_2'] += $i['sca2_3']+$i['scb2_2']+$i['scc2_3'];
            
            $alldatas["m_".$i['month']]['fumu_3'] += $i['sca3_0']+$i['scb3_0']+$i['scc3_0'];
            $alldatas["m_".$i['month']]['xiongdi_3'] += $i['sca3_1']+$i['scb3_1']+$i['scc3_1'];
            $alldatas["m_".$i['month']]['zufu_3'] += $i['sca3_2']+$i['scb3_2']+$i['scc3_2'];
            $alldatas["m_".$i['month']]['other_3'] += $i['sca3_3']+$i['scb3_2']+$i['scc3_3'];
        }
        $this->alldatas = $alldatas;
        
        $allTotals = array();
        foreach($total as $i)
        {
            $allTotals['zhusu'] += $i['total_zhusu'];
            $allTotals['zoudu'] += $i['total']-$i['total_zhusu'];
            $allTotals['liushou'] += $i['total_liushou'];
            $allTotals['feiliushou'] += $i['total']-$i['total_liushou'];
        }
        $this->allTotals = $allTotals;
        
        $allRTotal = array();
        foreach($data as $i)
        {
            $allRTotal['fumu_0'] += $i['sca0_0']+$i['scb0_0']+$i['scc0_0'];
            $allRTotal['xiongdi_0'] += $i['sca0_1']+$i['scb0_1']+$i['scc0_1'];
            $allRTotal['zufu_0'] += $i['sca0_2']+$i['scb0_2']+$i['scc0_2'];
            $allRTotal['other_0'] += $i['sca0_3']+$i['scb0_2']+$i['scc0_3'];
            
            $allRTotal['fumu_1'] += $i['sca1_0']+$i['scb1_0']+$i['scc1_0'];
            $allRTotal['xiongdi_1'] += $i['sca1_1']+$i['scb1_1']+$i['scc1_1'];
            $allRTotal['zufu_1'] += $i['sca1_2']+$i['scb1_2']+$i['scc1_2'];
            $allRTotal['other_1'] += $i['sca1_3']+$i['scb1_2']+$i['scc1_3'];
            
            $allRTotal['fumu_2'] += $i['sca2_0']+$i['scb2_0']+$i['scc2_0'];
            $allRTotal['xiongdi_2'] += $i['sca2_1']+$i['scb2_1']+$i['scc2_1'];
            $allRTotal['zufu_2'] += $i['sca2_2']+$i['scb2_2']+$i['scc2_2'];
            $allRTotal['other_2'] += $i['sca2_3']+$i['scb2_2']+$i['scc2_3'];
            
            $allRTotal['fumu_3'] += $i['sca3_0']+$i['scb3_0']+$i['scc3_0'];
            $allRTotal['xiongdi_3'] += $i['sca3_1']+$i['scb3_1']+$i['scc3_1'];
            $allRTotal['zufu_3'] += $i['sca3_2']+$i['scb3_2']+$i['scc3_2'];
            $allRTotal['other_3'] += $i['sca3_3']+$i['scb3_2']+$i['scc3_3'];
        }
        $this->allRTotal = $allRTotal;
        
		$this->display('tables/C03B.html');
	}
	
	
	
	function C03C(){
		/**
		C03C 亲情电话\视频\书信汇总统计表 
		*/
		
	  $schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		$term = $this->tTerms->find(array('id'=>$termid));
		 $sql = "SELECT SUM(ca0_0) AS sca0_0, SUM(ca0_1) AS sca0_1, SUM(ca0_2) AS sca0_2, SUM(ca0_3) AS sca0_3,
						 SUM(ca1_0) AS sca1_0, SUM(ca1_1) AS sca1_1, SUM(ca1_2) AS sca1_2, SUM(ca1_3) AS sca1_3,
							SUM(ca2_0) AS sca2_0, SUM(ca2_1) AS sca2_1, SUM(ca2_2) AS sca2_2, SUM(ca2_3) AS sca2_3,
							 SUM(ca3_0) AS sca3_0, SUM(ca3_1) AS sca3_1, SUM(ca3_2) AS sca3_2, SUM(ca3_3) AS sca3_3,
						SUM(cb0_0) AS scb0_0, SUM(cb0_1) AS scb0_1, SUM(cb0_2) AS scb0_2, SUM(cb0_3) AS scb0_3,
						 SUM(cb1_0) AS scb1_0, SUM(cb1_1) AS scb1_1, SUM(cb1_2) AS scb1_2, SUM(cb1_3) AS scb1_3,
							SUM(cb2_0) AS scb2_0, SUM(cb2_1) AS scb2_1, SUM(cb2_2) AS scb2_2, SUM(cb2_3) AS scb2_3,
							 SUM(cb3_0) AS scb3_0, SUM(cb3_1) AS scb3_1, SUM(cb3_2) AS scb3_2, SUM(cb3_3) AS scb3_3,
						SUM(cc0_0) AS scc0_0, SUM(cc0_1) AS scc0_1, SUM(cc0_2) AS scc0_2, SUM(cc0_3) AS scc0_3,
						 SUM(cc1_0) AS scc1_0, SUM(cc1_1) AS scc1_1, SUM(cc1_2) AS scc1_2, SUM(cc1_3) AS scc1_3,
							SUM(cc2_0) AS scc2_0, SUM(cc2_1) AS scc2_1, SUM(cc2_2) AS scc2_2, SUM(cc2_3) AS scc2_3,
							 SUM(cc3_0) AS scc3_0, SUM(cc3_1) AS scc3_1, SUM(cc3_2) AS scc3_2, SUM(cc3_3) AS scc3_3,
						MONTH(cdate) AS month, schoolid, schoolname
						FROM class_statistics_each_day LEFT JOIN classes ON classid=classes.id
						LEFT JOIN schools ON schools.id=schoolid
						WHERE cdate BETWEEN '".$term['cfrom']."' AND '".$term['cto']."'
						GROUP BY MONTH(cdate), schoolid ORDER BY schoolid DESC";
        
        $data = $this->tClassStatisticsEachDay->findSql($sql);
			
        
        $datas = array();
        foreach($data as $i)
        {
            $datas[$i['month'].'_'.$i['schoolid']] = $i;        
        }
        $this->datas = $datas;
        
        $mfrom = date('n', strtotime($term['cfrom']));
        $mto = date('n', strtotime($term['cto']));
        
        $months = array();
        $monthnums = array('一月', '二月', '三月', '四月', '五月', 
        '六月', '七月', '八月', '九月', '十月', 
        '十一月', '十二月');
        $i = $mfrom;
        while($i != $mto)
        {
            array_push($months, array('num'=>$i, 'text'=>$monthnums[$i-1]));
            if(++$i==13) $i=1;
        }
        array_push($months, array('num'=>$i, 'text'=>$monthnums[$i-1]));
        
        $this->months = $months;
        $this->schools = $this->tSchools->findAll();
        
        
        //****************************************
        //下面开始统计人数，小计，以及总计
        //****************************************
        
        //人数
        $sql = "SELECT SUM((0+a0_0)+(0+a1_0)) AS total,
                        SUM((0+a0_1)+(0+a0_2)+(0+a0_3)+(0+a1_1)+(0+a1_2)+(0+a1_3)) AS total_liushou,
                        SUM((0+a2_0)+(0+a3_0)) AS total_zhusu,
                        schoolid,
                        schoolname,
												zone
                FROM class_statistics_each_term LEFT JOIN classes ON classid=classes.id
								LEFT JOIN schools ON schoolid=schools.id
                WHERE termid=$termid
				GROUP BY schoolid
                ORDER BY schoolid DESC";
        $total = $this->tClassStatisticsEachTerm->findSql($sql);
        $totals = array();
        foreach($total as $i)
        {
            $totals['c_'.$i['schoolid']] = $i;        
        }
        $this->totals = $totals;
        
        //小计
        $rtotal = array();
        foreach($data as $i)
        {
            $rtotal["c_".$i['schoolid']]['fumu_0'] += $i['sca0_0']+$i['scb0_0']+$i['scc0_0'];
            $rtotal["c_".$i['schoolid']]['xiongdi_0'] += $i['sca0_1']+$i['scb0_1']+$i['scc0_1'];
            $rtotal["c_".$i['schoolid']]['zufu_0'] += $i['sca0_2']+$i['scb0_2']+$i['scc0_2'];
            $rtotal["c_".$i['schoolid']]['other_0'] += $i['sca0_3']+$i['scb0_2']+$i['scc0_3'];
            
            $rtotal["c_".$i['schoolid']]['fumu_1'] += $i['sca1_0']+$i['scb1_0']+$i['scc1_0'];
            $rtotal["c_".$i['schoolid']]['xiongdi_1'] += $i['sca1_1']+$i['scb1_1']+$i['scc1_1'];
            $rtotal["c_".$i['schoolid']]['zufu_1'] += $i['sca1_2']+$i['scb1_2']+$i['scc1_2'];
            $rtotal["c_".$i['schoolid']]['other_1'] += $i['sca1_3']+$i['scb1_2']+$i['scc1_3'];
            
            $rtotal["c_".$i['schoolid']]['fumu_2'] += $i['sca2_0']+$i['scb2_0']+$i['scc2_0'];
            $rtotal["c_".$i['schoolid']]['xiongdi_2'] += $i['sca2_1']+$i['scb2_1']+$i['scc2_1'];
            $rtotal["c_".$i['schoolid']]['zufu_2'] += $i['sca2_2']+$i['scb2_2']+$i['scc2_2'];
            $rtotal["c_".$i['schoolid']]['other_2'] += $i['sca2_3']+$i['scb2_2']+$i['scc2_3'];
            
            $rtotal["c_".$i['schoolid']]['fumu_3'] += $i['sca3_0']+$i['scb3_0']+$i['scc3_0'];
            $rtotal["c_".$i['schoolid']]['xiongdi_3'] += $i['sca3_1']+$i['scb3_1']+$i['scc3_1'];
            $rtotal["c_".$i['schoolid']]['zufu_3'] += $i['sca3_2']+$i['scb3_2']+$i['scc3_2'];
            $rtotal["c_".$i['schoolid']]['other_3'] += $i['sca3_3']+$i['scb3_2']+$i['scc3_3'];
            
        }
				
        $this->rtotal = $rtotal;
        
        //总计
        $alldatas = array();
        foreach($data as $i)
        {
            $alldatas["m_".$i['month']]['fumu_0'] += $i['sca0_0']+$i['scb0_0']+$i['scc0_0'];
            $alldatas["m_".$i['month']]['xiongdi_0'] += $i['sca0_1']+$i['scb0_1']+$i['scc0_1'];
            $alldatas["m_".$i['month']]['zufu_0'] += $i['sca0_2']+$i['scb0_2']+$i['scc0_2'];
            $alldatas["m_".$i['month']]['other_0'] += $i['sca0_3']+$i['scb0_2']+$i['scc0_3'];
            
            $alldatas["m_".$i['month']]['fumu_1'] += $i['sca1_0']+$i['scb1_0']+$i['scc1_0'];
            $alldatas["m_".$i['month']]['xiongdi_1'] += $i['sca1_1']+$i['scb1_1']+$i['scc1_1'];
            $alldatas["m_".$i['month']]['zufu_1'] += $i['sca1_2']+$i['scb1_2']+$i['scc1_2'];
            $alldatas["m_".$i['month']]['other_1'] += $i['sca1_3']+$i['scb1_2']+$i['scc1_3'];
            
            $alldatas["m_".$i['month']]['fumu_2'] += $i['sca2_0']+$i['scb2_0']+$i['scc2_0'];
            $alldatas["m_".$i['month']]['xiongdi_2'] += $i['sca2_1']+$i['scb2_1']+$i['scc2_1'];
            $alldatas["m_".$i['month']]['zufu_2'] += $i['sca2_2']+$i['scb2_2']+$i['scc2_2'];
            $alldatas["m_".$i['month']]['other_2'] += $i['sca2_3']+$i['scb2_2']+$i['scc2_3'];
            
            $alldatas["m_".$i['month']]['fumu_3'] += $i['sca3_0']+$i['scb3_0']+$i['scc3_0'];
            $alldatas["m_".$i['month']]['xiongdi_3'] += $i['sca3_1']+$i['scb3_1']+$i['scc3_1'];
            $alldatas["m_".$i['month']]['zufu_3'] += $i['sca3_2']+$i['scb3_2']+$i['scc3_2'];
            $alldatas["m_".$i['month']]['other_3'] += $i['sca3_3']+$i['scb3_2']+$i['scc3_3'];
        }
        $this->alldatas = $alldatas;
        
        $allTotals = array();
        foreach($total as $i)
        {
            $allTotals['zhusu'] += $i['total_zhusu'];
            $allTotals['zoudu'] += $i['total']-$i['total_zhusu'];
            $allTotals['liushou'] += $i['total_liushou'];
            $allTotals['feiliushou'] += $i['total']-$i['total_liushou'];
        }
        $this->allTotals = $allTotals;
        
        $allRTotal = array();
        foreach($data as $i)
        {
            $allRTotal['fumu_0'] += $i['sca0_0']+$i['scb0_0']+$i['scc0_0'];
            $allRTotal['xiongdi_0'] += $i['sca0_1']+$i['scb0_1']+$i['scc0_1'];
            $allRTotal['zufu_0'] += $i['sca0_2']+$i['scb0_2']+$i['scc0_2'];
            $allRTotal['other_0'] += $i['sca0_3']+$i['scb0_2']+$i['scc0_3'];
            
            $allRTotal['fumu_1'] += $i['sca1_0']+$i['scb1_0']+$i['scc1_0'];
            $allRTotal['xiongdi_1'] += $i['sca1_1']+$i['scb1_1']+$i['scc1_1'];
            $allRTotal['zufu_1'] += $i['sca1_2']+$i['scb1_2']+$i['scc1_2'];
            $allRTotal['other_1'] += $i['sca1_3']+$i['scb1_2']+$i['scc1_3'];
            
            $allRTotal['fumu_2'] += $i['sca2_0']+$i['scb2_0']+$i['scc2_0'];
            $allRTotal['xiongdi_2'] += $i['sca2_1']+$i['scb2_1']+$i['scc2_1'];
            $allRTotal['zufu_2'] += $i['sca2_2']+$i['scb2_2']+$i['scc2_2'];
            $allRTotal['other_2'] += $i['sca2_3']+$i['scb2_2']+$i['scc2_3'];
            
            $allRTotal['fumu_3'] += $i['sca3_0']+$i['scb3_0']+$i['scc3_0'];
            $allRTotal['xiongdi_3'] += $i['sca3_1']+$i['scb3_1']+$i['scc3_1'];
            $allRTotal['zufu_3'] += $i['sca3_2']+$i['scb3_2']+$i['scc3_2'];
            $allRTotal['other_3'] += $i['sca3_3']+$i['scb3_2']+$i['scc3_3'];
        }
        $this->allRTotal = $allRTotal;
        
		$this->display('tables/C03C.html');
	}
	
	
	

	function M02B(){
	/*学生信息统计表
	 * $schoolid
	 * termid
	 *
	 */

		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		/********下面开始处理数据库的数据***************/
		$sql_classes="select * from classes where schoolid=$schoolid ";
		$ary_classes=$this->db->findSql($sql_classes);//得到学校下的班级
		
		foreach($ary_classes as $item){
			$ary_classid[]=$item["id"];
		}//本校所有的班id 
		
		$ary_list=array();
		foreach($ary_classid as $ary){
			$sql="select * from class_statistics_each_term where classid=$ary and termid=$termid";
			

			$str_classname="";
			foreach($ary_classes as $c_item){
				if($c_item["id"]==$ary){
					$str_classname=$c_item["classname"];
				}
			}
			
			
			$row_ary=$this->db->findSql($sql);
			
			if($row_ary){
				$row=$row_ary[0];
				array_unshift($row,$str_classname);
			}else{
				$row=array($str_classname);
			}
			
			$ary_list[]=$row;
		}
		
		$type_list=array("男生","女生","住宿男生","住宿女生");
		$this->ary_list=$ary_list;
		
		$this->type=$type_list;
		$this->display('tables/M02B.html');
	//M06B 
	}
	
	
	

	function M06C (){
		//M06C 
		
	/*各学校学生信息汇总表
	 * $schoolid
	 * termid
	 *
	 */
		//$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		
		
		/********下面开始处理数据库的数据***************/
		$sql_school="select * from schools";
		
		$ary_schools=$this->db->findSql($sql_school);//得到所有的学校
		
		$ary_list=array();
		
		foreach($ary_schools as $sch){
			
			$sql_classes="select * from classes where schoolid=".$sch["id"];
			$ary_classes=$this->db->findSql($sql_classes);
			
			$sql="select * from class_statistics_each_term where classid in (select id from classes where schoolid=".$sch["id"].") and termid=$termid";
				
				$str_schoolname="";
				foreach($ary_schools as $s_item){
					if($s_item["id"]==$sch["id"]){
						$str_schoolname=array($s_item["schoolname"],$s_item["zone"]?$s_item["zone"]:'-');
						
					}
				}
				
				$row_ary=$this->db->findSql($sql);
				$row=array();
	
				if($row_ary){
					foreach($row_ary as $item){
						$a0_0+=$item["a0_0"];
						$a0_1+=$item["a0_1"];
						$a0_2+=$item["a0_2"];
						$a0_3+=$item["a0_3"];
						$a0_4+=$item["a0_4"];
						$a0_5+=$item["a0_5"];
						$a0_6+=$item["a0_6"];
						$a0_7_1+=$item["a0_7_1"];
						$a0_7_2+=$item["a0_7_2"];
						$a0_8+=$item["a0_8"];
						
						$a1_0+=$item["a1_0"];
						$a1_1+=$item["a1_1"];
						$a1_2+=$item["a1_2"];
						$a1_3+=$item["a1_3"];
						$a1_4+=$item["a1_4"];
						$a1_5+=$item["a1_5"];
						$a1_6+=$item["a1_6"];
						$a1_7_1+=$item["a1_7_1"];
						$a1_7_2+=$item["a1_7_2"];
						$a1_8+=$item["a1_8"];
						
						$a2_0+=$item["a2_0"];
						$a2_1+=$item["a2_1"];
						$a2_2+=$item["a2_2"];
						$a2_3+=$item["a2_3"];
						$a2_4+=$item["a2_4"];
						$a2_5+=$item["a2_5"];
						$a2_6+=$item["a2_6"];
						$a2_7_1+=$item["a2_7_1"];
						$a2_7_2+=$item["a2_7_2"];
						$a2_8+=$item["a2_8"];
						
						$a3_0+=$item["a3_0"];
						$a3_1+=$item["a3_1"];
						$a3_2+=$item["a3_2"];
						$a3_3+=$item["a3_3"];
						$a3_4+=$item["a3_4"];
						$a3_5+=$item["a3_5"];
						$a3_6+=$item["a3_6"];
						$a3_7_1+=$item["a3_7_1"];
						$a3_7_2+=$item["a3_7_2"];
						$a3_8+=$item["a3_8"];
						
						$row=array(
							'a0_0'=>$a0_0,'a0_1'=>$a0_1,'a0_2'=>$a0_2,'a0_3'=>$a0_3,'a0_4'=>$a0_4,'a0_5'=>$a0_5,'a0_6'=>$a0_6,'a0_7_1'=>$a0_7_1,'a0_7_2'=>$a0_7_2,'a0_8'=>$a0_8,'a1_0'=>$a1_0,'a1_1'=>$a1_1,'a1_2'=>$a1_2,'a1_3'=>$a1_3,'a1_4'=>$a1_4,'a1_5'=>$a1_5,'a1_6'=>$a1_6,'a1_7_1'=>$a1_7_1,'a1_7_2'=>$a1_7_2,'a1_8'=>$a1_8,'a2_0'=>$a2_0,'a2_1'=>$a2_1,'a2_2'=>$a2_2,'a2_3'=>$a2_3,'a2_4'=>$a2_4,'a2_5'=>$a2_5,'a2_6'=>$a2_6,'a2_7_1'=>$a2_7_1,'a2_7_2'=>$a2_7_2,'a2_8'=>$a2_8,'a3_0'=>$a3_0,'a3_1'=>$a3_1,'a0_3'=>$a3_2,'a3_3'=>$a3_3,'a3_4'=>$a3_4,'a3_5'=>$a3_5,'a3_6'=>$a3_6,'a3_7_1'=>$a3_7_1,'a3_7_2'=>$a3_7_2,'a3_8'=>$a3_8
							
						);
					}
					
				}
				
				array_unshift($row,$str_schoolname);
				$ary_list[]=$row;
	  }
		$type_list=array("男生","女生","住宿男生","住宿女生");
		$this->ary_list=$ary_list;

		$this->type=$type_list;
		$this->display('tables/M06C.html');
	}
	
	function ppt(){
		
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;  
		$sql_terms="select * from terms where id =$termid ";
		$ary_terms=$this->db->findSql($sql_terms);//得到起始时间
		$cfrom=$ary_terms[0]['cfrom'];
		$cto=$ary_terms[0]['cto'];
		
		$id=$_GET['id'];
		$title=$_GET['title'];
		$this->top=$title;
		
		$sql="select * from super_config02 where id=$id";
		$sql_item="select * from  super_config01";
		$sql_rows="select * from actions where r1=$id and cdate>='$cfrom' and cdate<='$cto' ";
		$item_list=$this->db->findSql($sql_item);
		$item_type=$this->db->findSql($sql);
		$ary_list=$this->db->findSql($sql_rows);
		if($item_type){
			$title.=$item_type[0]["value"];
		}
		
		
		$this->id=$id;
		$this->title=$title;
		$this->ary_list=$ary_list;
	 $this->display('tables/ppt.html');
	}
	
	
	
	function jiaoxue(){
		$termid = $this->spArgs('termid', -1);//默认第一学期
		$this->termid = $termid;  
		$id=$_GET['id'];
		$top=$_GET['title'];
		$this->top=$top;
		$this->id=$id;
		$str="";
		$unitname="";
		switch($id){
			case 1:
			$str="教师结对子";
			$unitname="file_1";
			break;
			case 2:
			$str="课程改革";
			$unitname="file_2";
			break;
			case 3:
			$str="样本教材";
			$unitname="file_3";
			break;
		}
		
		$sql="select * from files where part=2 and termid=$termid and  unitname='$unitname'";
	  $ary_list=$this->db->findSql($sql);
		$this->title=$top.$str;
		if($ary_list){
			$this->ary_list=$ary_list;
		}
		$this->display('tables/jiaoxue.html');
	}
	
	
	function zhidu(){
		$termid = $this->spArgs('termid', -1);//默认第一学期
		$this->termid = $termid;  
		$id=$_GET['id'];
		$top=$_GET['title'];
		$this->top=$top;
		$this->id=$id;
		$str="";
		$unitname="";
	
		switch($id){
			case 1:
			$str="硬件信息";
			$unitname="file_1";
			break;
			case 2:
			$str="组织分工";
			$unitname="file_2";
			break;
			case 3:
			$str="作息分工";
			$unitname="file_3";
			break;
			case 4:
			$str="国旗护卫队管理制度";
			$unitname="file_4";
			break;
			case 5:
			$str="少先队管理制度";
			$unitname="file_5";
			break;
			case 6:
			$str="少先队监督制度";
			$unitname="file_6";
			break;
			case 7:
			$str="大课间活动制度";
			$unitname="file_7";
			break;
			case 8:
			$str="代理家长管理制度";
			$unitname="file_8";
			break;
			case 9:
			$str="结对帮扶管理制度";
			$unitname="file_9";
			break;
			case 10:
			$str="留守儿童教育期刊";
			$unitname="file_10";
			break;
			case 11:
			$str="校园文化建设";
			$unitname="file_11";
			break;
		
		}
		
		$sql="select * from files where part=1 and termid=$termid and  unitname='$unitname'";
	  $ary_list=$this->db->findSql($sql);
		$this->title=$top.$str;
		if($ary_list){
			$this->ary_list=$ary_list;
		}
		
		$this->display('tables/zhidu.html');
	}
	
	function export_term(){
		$schoolid = $this->schoolid;    //取当前学校ID
		//取传递来的termid（学期ID）参数，如果没有则为-1（-1表示没有任何学期，是空值）
		$termid = $this->spArgs('termid', 1);//默认第一学期
		$this->termid = $termid;   
		$sql="select * from terms where id=$termid";
		$ary_terms=$this->db->findSql($sql);//当前学期
		$this->the_term=$ary_terms[0];
		
		$sql_term="select * from class_statistics_each_term where termid=$termid and classid in(select id from classes where schoolid=$schoolid)";

		$ary_list=$this->db->findSql($sql_term);
		$a1=$a2=$a3=$a4=$a5=$a6=$a7=$a8=$a9=$a10=$b1=$b2=$b3=$b4=$b5=$b6=0;
		$c1=$c2=$c3=$c4=$c5=$c6=$c7=$c8=$c9=$c10=$d1=$d2=$d3=$d4=$d5=$d6=0;

		foreach($ary_list as $item){
			$a1+=$item["a0_0"]+$item["a1_0"];//全校人数
			$a2+=$item["a0_1"]+$item["a1_1"];//全校父亲在外人数
			$a3+=$item["a0_2"]+$item["a1_2"];//全校母新在外人数
			$a4+=$item["a0_3"]+$item["a1_3"];//全校父母双方在外人数
			
			$a5+=$item["a0_1"]+$item["a0_2"]+$item["a0_3"]+$item["a1_1"]+$item["a1_2"]+$item["a1_3"];//三者合计
			$a6+=$item["a0_4"]+$item["a1_4"];//隔代
			$a7+=$item["a0_5"]+$item["a1_5"];//亲友
			$a8+=$item["a0_6"]+$item["a1_6"];//寄养
			$a9+=$item["a0_7_1"]+$item["a1_7_1"]+$item["a0_7_2"]+$item["a1_7_2"];//单亲家庭
			$a10+=$item["a0_8"]+$item["a1_8"];//孤儿人数
			
			$c1+=$item["a2_0"]+$item["a3_0"];//全校人数
			$c2+=$item["a2_1"]+$item["a3_1"];//全校父亲在外人数
			$c3+=$item["a2_2"]+$item["a3_2"];//全校母新在外人数
			$c4+=$item["a2_3"]+$item["a3_3"];//全校父母双方在外人数
			$c5+=$item["a2_1"]+$item["a2_2"]+$item["a2_3"]+$item["a3_1"]+$item["a3_2"]+$item["a3_3"];//三者合计
			$c6+=$item["a2_4"]+$item["a3_4"];//隔代
			$c7+=$item["a2_5"]+$item["a3_5"];//亲友
			$c8+=$item["a2_6"]+$item["a3_6"];//寄养
			$c9+=$item["a2_7_1"]+$item["a2_7_1"]+$item["a3_7_2"]+$item["a3_7_2"];//单亲家庭
			$c10+=$item["a2_8"]+$item["a3_8"];//孤儿人数
		}

		$b1=round(($a2/$a1)*100)."%";// 全校父亲在外人数
		$b2=round(($a3/$a1)*100)."%";// 全校母新在外人数
		$b3=round(($a4/$a1)*100)."%";// 父母双方在外比例 
		$b4=round(($a5/$a1)*100)."%";//三者合计比例
		$b5=round(($a9/$a1)*100)."%";//单亲比例
		$b6=round(($a10/$a1)*100)."%";//孤儿比例
		
		
		$d1=round(($c2/$c1)*100)."%";//父亲在外比例
		$d2=round(($c3/$c1)*100)."%";//母亲在外比例
		$d3=round(($c4/$c1)*100)."%";//父母双方在外比例
		$d4=round(($c5/$c1)*100)."%";//三者合计比例
		$d5=round(($c9/$c1)*100)."%";//单亲比例
		$d6=round(($c10/$c1)*100)."%";//孤儿比例
	
		$ary_one=array($a1,$a4,$b3,$a2,$b1,$a3,$b2,$a5,$b4,$a6,$a7,$a8,$a9,$b5,$a10,$b6);
		$ary_two=array($c1,$c4,$d3,$c2,$d1,$c3,$d2,$c5,$d4,$c6,$c7,$c8,$c9,$d5,$c10,$d6);

		$this->one_row=$ary_one;
		$this->two_row=$ary_two;
		$this->display('export_index.html');
	}
	
	
	function total_info(){
		$this->display('total_info.html');
	}
	
}



